diff --git a/.gitignore b/.gitignore
index 81e37c76..cfb3e11d 100644
--- a/.gitignore
+++ b/.gitignore
@@ -5,4 +5,4 @@ dist
tsconfig.tsbuildinfo
uploads
coverage
-coverage-badges
\ No newline at end of file
+coverage-badges/
\ No newline at end of file
diff --git a/README.md b/README.md
index cc92df15..bd630fb2 100644
--- a/README.md
+++ b/README.md
@@ -27,7 +27,6 @@
-
diff --git a/docs/README.md b/docs/README.md
index aaee541a..13a69f27 100644
--- a/docs/README.md
+++ b/docs/README.md
@@ -29,7 +29,6 @@ medusa-extender / [Exports](modules.md)
-
diff --git a/docs/classes/Medusa.Medusa-1.md b/docs/classes/Medusa.Medusa-1.md
index b4dbc38d..ee8ef82e 100644
--- a/docs/classes/Medusa.Medusa-1.md
+++ b/docs/classes/Medusa.Medusa-1.md
@@ -37,7 +37,7 @@ Load medusa and apply all components
#### Defined in
-[src/Medusa.ts:38](https://github.com/adrien2p/medusa-extender/blob/c2d2cfc/src/Medusa.ts#L38)
+[src/Medusa.ts:37](https://github.com/adrien2p/medusa-extender/blob/575c26f/src/Medusa.ts#L37)
## Properties
@@ -47,7 +47,7 @@ Load medusa and apply all components
#### Defined in
-[src/Medusa.ts:31](https://github.com/adrien2p/medusa-extender/blob/c2d2cfc/src/Medusa.ts#L31)
+[src/Medusa.ts:30](https://github.com/adrien2p/medusa-extender/blob/575c26f/src/Medusa.ts#L30)
___
@@ -57,7 +57,7 @@ ___
#### Defined in
-[src/Medusa.ts:32](https://github.com/adrien2p/medusa-extender/blob/c2d2cfc/src/Medusa.ts#L32)
+[src/Medusa.ts:31](https://github.com/adrien2p/medusa-extender/blob/575c26f/src/Medusa.ts#L31)
## Methods
@@ -77,7 +77,7 @@ ___
#### Defined in
-[src/Medusa.ts:46](https://github.com/adrien2p/medusa-extender/blob/c2d2cfc/src/Medusa.ts#L46)
+[src/Medusa.ts:45](https://github.com/adrien2p/medusa-extender/blob/575c26f/src/Medusa.ts#L45)
___
@@ -91,4 +91,4 @@ ___
#### Defined in
-[src/Medusa.ts:76](https://github.com/adrien2p/medusa-extender/blob/c2d2cfc/src/Medusa.ts#L76)
+[src/Medusa.ts:82](https://github.com/adrien2p/medusa-extender/blob/575c26f/src/Medusa.ts#L82)
diff --git a/docs/classes/decorators_onMedusaEntityEvent_decorator.OnMedusaEntityEvent.md b/docs/classes/decorators_onMedusaEntityEvent_decorator.OnMedusaEntityEvent.md
index e5763fa2..646c7565 100644
--- a/docs/classes/decorators_onMedusaEntityEvent_decorator.OnMedusaEntityEvent.md
+++ b/docs/classes/decorators_onMedusaEntityEvent_decorator.OnMedusaEntityEvent.md
@@ -45,7 +45,7 @@
#### Defined in
-[src/decorators/onMedusaEntityEvent.decorator.ts:42](https://github.com/adrien2p/medusa-extender/blob/c2d2cfc/src/decorators/onMedusaEntityEvent.decorator.ts#L42)
+[src/decorators/onMedusaEntityEvent.decorator.ts:42](https://github.com/adrien2p/medusa-extender/blob/575c26f/src/decorators/onMedusaEntityEvent.decorator.ts#L42)
## Properties
@@ -55,7 +55,7 @@
#### Defined in
-[src/decorators/onMedusaEntityEvent.decorator.ts:40](https://github.com/adrien2p/medusa-extender/blob/c2d2cfc/src/decorators/onMedusaEntityEvent.decorator.ts#L40)
+[src/decorators/onMedusaEntityEvent.decorator.ts:40](https://github.com/adrien2p/medusa-extender/blob/575c26f/src/decorators/onMedusaEntityEvent.decorator.ts#L40)
___
@@ -65,7 +65,7 @@ ___
#### Defined in
-[src/decorators/onMedusaEntityEvent.decorator.ts:39](https://github.com/adrien2p/medusa-extender/blob/c2d2cfc/src/decorators/onMedusaEntityEvent.decorator.ts#L39)
+[src/decorators/onMedusaEntityEvent.decorator.ts:39](https://github.com/adrien2p/medusa-extender/blob/575c26f/src/decorators/onMedusaEntityEvent.decorator.ts#L39)
## Accessors
@@ -79,7 +79,7 @@ ___
#### Defined in
-[src/decorators/onMedusaEntityEvent.decorator.ts:50](https://github.com/adrien2p/medusa-extender/blob/c2d2cfc/src/decorators/onMedusaEntityEvent.decorator.ts#L50)
+[src/decorators/onMedusaEntityEvent.decorator.ts:50](https://github.com/adrien2p/medusa-extender/blob/575c26f/src/decorators/onMedusaEntityEvent.decorator.ts#L50)
___
@@ -93,7 +93,7 @@ ___
#### Defined in
-[src/decorators/onMedusaEntityEvent.decorator.ts:46](https://github.com/adrien2p/medusa-extender/blob/c2d2cfc/src/decorators/onMedusaEntityEvent.decorator.ts#L46)
+[src/decorators/onMedusaEntityEvent.decorator.ts:46](https://github.com/adrien2p/medusa-extender/blob/575c26f/src/decorators/onMedusaEntityEvent.decorator.ts#L46)
## Methods
@@ -120,7 +120,7 @@ ___
#### Defined in
-[src/decorators/onMedusaEntityEvent.decorator.ts:70](https://github.com/adrien2p/medusa-extender/blob/c2d2cfc/src/decorators/onMedusaEntityEvent.decorator.ts#L70)
+[src/decorators/onMedusaEntityEvent.decorator.ts:70](https://github.com/adrien2p/medusa-extender/blob/575c26f/src/decorators/onMedusaEntityEvent.decorator.ts#L70)
___
@@ -146,7 +146,7 @@ ___
#### Defined in
-[src/decorators/onMedusaEntityEvent.decorator.ts:58](https://github.com/adrien2p/medusa-extender/blob/c2d2cfc/src/decorators/onMedusaEntityEvent.decorator.ts#L58)
+[src/decorators/onMedusaEntityEvent.decorator.ts:58](https://github.com/adrien2p/medusa-extender/blob/575c26f/src/decorators/onMedusaEntityEvent.decorator.ts#L58)
___
@@ -173,7 +173,7 @@ ___
#### Defined in
-[src/decorators/onMedusaEntityEvent.decorator.ts:84](https://github.com/adrien2p/medusa-extender/blob/c2d2cfc/src/decorators/onMedusaEntityEvent.decorator.ts#L84)
+[src/decorators/onMedusaEntityEvent.decorator.ts:84](https://github.com/adrien2p/medusa-extender/blob/575c26f/src/decorators/onMedusaEntityEvent.decorator.ts#L84)
___
@@ -199,7 +199,7 @@ ___
#### Defined in
-[src/decorators/onMedusaEntityEvent.decorator.ts:66](https://github.com/adrien2p/medusa-extender/blob/c2d2cfc/src/decorators/onMedusaEntityEvent.decorator.ts#L66)
+[src/decorators/onMedusaEntityEvent.decorator.ts:66](https://github.com/adrien2p/medusa-extender/blob/575c26f/src/decorators/onMedusaEntityEvent.decorator.ts#L66)
___
@@ -226,7 +226,7 @@ ___
#### Defined in
-[src/decorators/onMedusaEntityEvent.decorator.ts:77](https://github.com/adrien2p/medusa-extender/blob/c2d2cfc/src/decorators/onMedusaEntityEvent.decorator.ts#L77)
+[src/decorators/onMedusaEntityEvent.decorator.ts:77](https://github.com/adrien2p/medusa-extender/blob/575c26f/src/decorators/onMedusaEntityEvent.decorator.ts#L77)
___
@@ -252,7 +252,7 @@ ___
#### Defined in
-[src/decorators/onMedusaEntityEvent.decorator.ts:62](https://github.com/adrien2p/medusa-extender/blob/c2d2cfc/src/decorators/onMedusaEntityEvent.decorator.ts#L62)
+[src/decorators/onMedusaEntityEvent.decorator.ts:62](https://github.com/adrien2p/medusa-extender/blob/575c26f/src/decorators/onMedusaEntityEvent.decorator.ts#L62)
___
@@ -280,7 +280,7 @@ ___
#### Defined in
-[src/decorators/onMedusaEntityEvent.decorator.ts:91](https://github.com/adrien2p/medusa-extender/blob/c2d2cfc/src/decorators/onMedusaEntityEvent.decorator.ts#L91)
+[src/decorators/onMedusaEntityEvent.decorator.ts:91](https://github.com/adrien2p/medusa-extender/blob/575c26f/src/decorators/onMedusaEntityEvent.decorator.ts#L91)
___
@@ -300,4 +300,4 @@ ___
#### Defined in
-[src/decorators/onMedusaEntityEvent.decorator.ts:54](https://github.com/adrien2p/medusa-extender/blob/c2d2cfc/src/decorators/onMedusaEntityEvent.decorator.ts#L54)
+[src/decorators/onMedusaEntityEvent.decorator.ts:54](https://github.com/adrien2p/medusa-extender/blob/575c26f/src/decorators/onMedusaEntityEvent.decorator.ts#L54)
diff --git a/docs/classes/event_emmiter.Internals.CustomEventEmmiter.md b/docs/classes/event_emmiter.Internals.CustomEventEmmiter.md
index 91305983..117603ca 100644
--- a/docs/classes/event_emmiter.Internals.CustomEventEmmiter.md
+++ b/docs/classes/event_emmiter.Internals.CustomEventEmmiter.md
@@ -41,7 +41,7 @@ EventEmitter.constructor
#### Defined in
-[src/event-emmiter.ts:21](https://github.com/adrien2p/medusa-extender/blob/c2d2cfc/src/event-emmiter.ts#L21)
+[src/event-emmiter.ts:21](https://github.com/adrien2p/medusa-extender/blob/575c26f/src/event-emmiter.ts#L21)
## Properties
@@ -51,7 +51,7 @@ EventEmitter.constructor
#### Defined in
-[src/event-emmiter.ts:19](https://github.com/adrien2p/medusa-extender/blob/c2d2cfc/src/event-emmiter.ts#L19)
+[src/event-emmiter.ts:19](https://github.com/adrien2p/medusa-extender/blob/575c26f/src/event-emmiter.ts#L19)
## Methods
@@ -80,7 +80,7 @@ Emit an asynchrone event entity based and wait for the result.
#### Defined in
-[src/event-emmiter.ts:80](https://github.com/adrien2p/medusa-extender/blob/c2d2cfc/src/event-emmiter.ts#L80)
+[src/event-emmiter.ts:80](https://github.com/adrien2p/medusa-extender/blob/575c26f/src/event-emmiter.ts#L80)
___
@@ -110,7 +110,7 @@ Register a new event handler.
#### Defined in
-[src/event-emmiter.ts:31](https://github.com/adrien2p/medusa-extender/blob/c2d2cfc/src/event-emmiter.ts#L31)
+[src/event-emmiter.ts:31](https://github.com/adrien2p/medusa-extender/blob/575c26f/src/event-emmiter.ts#L31)
___
@@ -132,7 +132,7 @@ Apply all event handlers hold by the `listenerDescriptor`.
#### Defined in
-[src/event-emmiter.ts:43](https://github.com/adrien2p/medusa-extender/blob/c2d2cfc/src/event-emmiter.ts#L43)
+[src/event-emmiter.ts:43](https://github.com/adrien2p/medusa-extender/blob/575c26f/src/event-emmiter.ts#L43)
___
@@ -146,4 +146,4 @@ ___
#### Defined in
-[src/event-emmiter.ts:68](https://github.com/adrien2p/medusa-extender/blob/c2d2cfc/src/event-emmiter.ts#L68)
+[src/event-emmiter.ts:68](https://github.com/adrien2p/medusa-extender/blob/575c26f/src/event-emmiter.ts#L68)
diff --git a/docs/classes/metadata_reader.Internals.CustomMap.md b/docs/classes/metadata_reader.Internals.CustomMap.md
index 524757a9..af102c9f 100644
--- a/docs/classes/metadata_reader.Internals.CustomMap.md
+++ b/docs/classes/metadata_reader.Internals.CustomMap.md
@@ -84,4 +84,4 @@ Map.get
#### Defined in
-[src/metadata-reader.ts:5](https://github.com/adrien2p/medusa-extender/blob/c2d2cfc/src/metadata-reader.ts#L5)
+[src/metadata-reader.ts:5](https://github.com/adrien2p/medusa-extender/blob/575c26f/src/metadata-reader.ts#L5)
diff --git a/docs/classes/utils.Utils.md b/docs/classes/utils.Utils.md
index 86c2530c..1928f22e 100644
--- a/docs/classes/utils.Utils.md
+++ b/docs/classes/utils.Utils.md
@@ -13,14 +13,17 @@ Utilities helper methods.
- [constructor](utils.Utils.md#constructor)
+### Properties
+
+- [logs](utils.Utils.md#logs)
+
### Methods
- [attachOrReplaceEntitySubscriber](utils.Utils.md#attachorreplaceentitysubscriber)
-- [log](utils.Utils.md#log)
-- [logRoutes](utils.Utils.md#logroutes)
-- [printRoutes](utils.Utils.md#printroutes)
+- [displayLogs](utils.Utils.md#displaylogs)
+- [hydrateLog](utils.Utils.md#hydratelog)
+- [hydrateRouteLog](utils.Utils.md#hydrateroutelog)
- [repositoryMixin](utils.Utils.md#repositorymixin)
-- [splitRoutes](utils.Utils.md#splitroutes)
## Constructors
@@ -28,6 +31,16 @@ Utilities helper methods.
• **new Utils**()
+## Properties
+
+### logs
+
+▪ `Static` **logs**: `string`[][] = `[]`
+
+#### Defined in
+
+[src/utils.ts:13](https://github.com/adrien2p/medusa-extender/blob/575c26f/src/utils.ts#L13)
+
## Methods
### attachOrReplaceEntitySubscriber
@@ -56,23 +69,16 @@ Attach a new subscriber to a specific entities.
#### Defined in
-[src/utils.ts:37](https://github.com/adrien2p/medusa-extender/blob/c2d2cfc/src/utils.ts#L37)
+[src/utils.ts:40](https://github.com/adrien2p/medusa-extender/blob/575c26f/src/utils.ts#L40)
___
-### log
-
-▸ `Static` **log**(`context`, `description`, ...`variables`): `void`
-
-Prepare the log to be shown to be consistent everywhere.
+### displayLogs
-#### Parameters
+▸ `Static` **displayLogs**(): `void`
-| Name | Type | Description |
-| :------ | :------ | :------ |
-| `context` | `string` | Where the log comes from |
-| `description` | `string` | The description of the action logged |
-| `...variables` | `string`[] | The variable that populate the logs |
+**`internal`**
+Display the logs that has been registered during the build time.
#### Returns
@@ -80,21 +86,24 @@ Prepare the log to be shown to be consistent everywhere.
#### Defined in
-[src/utils.ts:68](https://github.com/adrien2p/medusa-extender/blob/c2d2cfc/src/utils.ts#L68)
+[src/utils.ts:90](https://github.com/adrien2p/medusa-extender/blob/575c26f/src/utils.ts#L90)
___
-### logRoutes
+### hydrateLog
-▸ `Static` **logRoutes**(`express`): `void`
+▸ `Static` **hydrateLog**(`context`, `description`, ...`variables`): `void`
-Log all the routes from the express instance.
+**`internal`**
+Prepare the log to be shown to be consistent everywhere.
#### Parameters
| Name | Type | Description |
| :------ | :------ | :------ |
-| `express` | `Express` | Express instance |
+| `context` | `string` | Where the log comes from |
+| `description` | `string` | The description of the action logged |
+| `...variables` | `string`[] | The variable that populate the logs |
#### Returns
@@ -102,20 +111,22 @@ Log all the routes from the express instance.
#### Defined in
-[src/utils.ts:58](https://github.com/adrien2p/medusa-extender/blob/c2d2cfc/src/utils.ts#L58)
+[src/utils.ts:64](https://github.com/adrien2p/medusa-extender/blob/575c26f/src/utils.ts#L64)
___
-### printRoutes
+### hydrateRouteLog
-▸ `Static` `Private` **printRoutes**(`path`, `layer`): `void`
+▸ `Static` **hydrateRouteLog**(`app`): `void`
+
+**`internal`**
+Prepare the logs the show all available routes on the app.
#### Parameters
| Name | Type |
| :------ | :------ |
-| `path` | `string`[] |
-| `layer` | `any` |
+| `app` | `Express` |
#### Returns
@@ -123,7 +134,7 @@ ___
#### Defined in
-[src/utils.ts:82](https://github.com/adrien2p/medusa-extender/blob/c2d2cfc/src/utils.ts#L82)
+[src/utils.ts:77](https://github.com/adrien2p/medusa-extender/blob/575c26f/src/utils.ts#L77)
___
@@ -153,24 +164,4 @@ Since it is not possible to use multiple extend, you can use that utilities to a
#### Defined in
-[src/utils.ts:17](https://github.com/adrien2p/medusa-extender/blob/c2d2cfc/src/utils.ts#L17)
-
-___
-
-### splitRoutes
-
-▸ `Static` `Private` **splitRoutes**(`thing`): `string` \| `string`[]
-
-#### Parameters
-
-| Name | Type |
-| :------ | :------ |
-| `thing` | `string` \| `RegExp` & { `fast_slash`: `boolean` } |
-
-#### Returns
-
-`string` \| `string`[]
-
-#### Defined in
-
-[src/utils.ts:102](https://github.com/adrien2p/medusa-extender/blob/c2d2cfc/src/utils.ts#L102)
+[src/utils.ts:20](https://github.com/adrien2p/medusa-extender/blob/575c26f/src/utils.ts#L20)
diff --git a/docs/interfaces/modules_monitoring.MonitoringOptions.md b/docs/interfaces/modules_monitoring.MonitoringOptions.md
index 7df68a3b..a1686bd9 100644
--- a/docs/interfaces/modules_monitoring.MonitoringOptions.md
+++ b/docs/interfaces/modules_monitoring.MonitoringOptions.md
@@ -35,7 +35,7 @@
#### Defined in
-[src/modules/monitoring.ts:15](https://github.com/adrien2p/medusa-extender/blob/c2d2cfc/src/modules/monitoring.ts#L15)
+[src/modules/monitoring.ts:15](https://github.com/adrien2p/medusa-extender/blob/575c26f/src/modules/monitoring.ts#L15)
___
@@ -45,7 +45,7 @@ ___
#### Defined in
-[src/modules/monitoring.ts:17](https://github.com/adrien2p/medusa-extender/blob/c2d2cfc/src/modules/monitoring.ts#L17)
+[src/modules/monitoring.ts:17](https://github.com/adrien2p/medusa-extender/blob/575c26f/src/modules/monitoring.ts#L17)
___
@@ -55,7 +55,7 @@ ___
#### Defined in
-[src/modules/monitoring.ts:12](https://github.com/adrien2p/medusa-extender/blob/c2d2cfc/src/modules/monitoring.ts#L12)
+[src/modules/monitoring.ts:12](https://github.com/adrien2p/medusa-extender/blob/575c26f/src/modules/monitoring.ts#L12)
___
@@ -65,7 +65,7 @@ ___
#### Defined in
-[src/modules/monitoring.ts:19](https://github.com/adrien2p/medusa-extender/blob/c2d2cfc/src/modules/monitoring.ts#L19)
+[src/modules/monitoring.ts:19](https://github.com/adrien2p/medusa-extender/blob/575c26f/src/modules/monitoring.ts#L19)
___
@@ -75,7 +75,7 @@ ___
#### Defined in
-[src/modules/monitoring.ts:7](https://github.com/adrien2p/medusa-extender/blob/c2d2cfc/src/modules/monitoring.ts#L7)
+[src/modules/monitoring.ts:7](https://github.com/adrien2p/medusa-extender/blob/575c26f/src/modules/monitoring.ts#L7)
___
@@ -85,7 +85,7 @@ ___
#### Defined in
-[src/modules/monitoring.ts:8](https://github.com/adrien2p/medusa-extender/blob/c2d2cfc/src/modules/monitoring.ts#L8)
+[src/modules/monitoring.ts:8](https://github.com/adrien2p/medusa-extender/blob/575c26f/src/modules/monitoring.ts#L8)
___
@@ -95,7 +95,7 @@ ___
#### Defined in
-[src/modules/monitoring.ts:13](https://github.com/adrien2p/medusa-extender/blob/c2d2cfc/src/modules/monitoring.ts#L13)
+[src/modules/monitoring.ts:13](https://github.com/adrien2p/medusa-extender/blob/575c26f/src/modules/monitoring.ts#L13)
___
@@ -105,7 +105,7 @@ ___
#### Defined in
-[src/modules/monitoring.ts:14](https://github.com/adrien2p/medusa-extender/blob/c2d2cfc/src/modules/monitoring.ts#L14)
+[src/modules/monitoring.ts:14](https://github.com/adrien2p/medusa-extender/blob/575c26f/src/modules/monitoring.ts#L14)
___
@@ -115,7 +115,7 @@ ___
#### Defined in
-[src/modules/monitoring.ts:18](https://github.com/adrien2p/medusa-extender/blob/c2d2cfc/src/modules/monitoring.ts#L18)
+[src/modules/monitoring.ts:18](https://github.com/adrien2p/medusa-extender/blob/575c26f/src/modules/monitoring.ts#L18)
___
@@ -125,7 +125,7 @@ ___
#### Defined in
-[src/modules/monitoring.ts:10](https://github.com/adrien2p/medusa-extender/blob/c2d2cfc/src/modules/monitoring.ts#L10)
+[src/modules/monitoring.ts:10](https://github.com/adrien2p/medusa-extender/blob/575c26f/src/modules/monitoring.ts#L10)
___
@@ -135,7 +135,7 @@ ___
#### Defined in
-[src/modules/monitoring.ts:9](https://github.com/adrien2p/medusa-extender/blob/c2d2cfc/src/modules/monitoring.ts#L9)
+[src/modules/monitoring.ts:9](https://github.com/adrien2p/medusa-extender/blob/575c26f/src/modules/monitoring.ts#L9)
___
@@ -145,7 +145,7 @@ ___
#### Defined in
-[src/modules/monitoring.ts:11](https://github.com/adrien2p/medusa-extender/blob/c2d2cfc/src/modules/monitoring.ts#L11)
+[src/modules/monitoring.ts:11](https://github.com/adrien2p/medusa-extender/blob/575c26f/src/modules/monitoring.ts#L11)
___
@@ -155,7 +155,7 @@ ___
#### Defined in
-[src/modules/monitoring.ts:6](https://github.com/adrien2p/medusa-extender/blob/c2d2cfc/src/modules/monitoring.ts#L6)
+[src/modules/monitoring.ts:6](https://github.com/adrien2p/medusa-extender/blob/575c26f/src/modules/monitoring.ts#L6)
## Methods
@@ -177,7 +177,7 @@ ___
#### Defined in
-[src/modules/monitoring.ts:20](https://github.com/adrien2p/medusa-extender/blob/c2d2cfc/src/modules/monitoring.ts#L20)
+[src/modules/monitoring.ts:20](https://github.com/adrien2p/medusa-extender/blob/575c26f/src/modules/monitoring.ts#L20)
___
@@ -199,4 +199,4 @@ ___
#### Defined in
-[src/modules/monitoring.ts:16](https://github.com/adrien2p/medusa-extender/blob/c2d2cfc/src/modules/monitoring.ts#L16)
+[src/modules/monitoring.ts:16](https://github.com/adrien2p/medusa-extender/blob/575c26f/src/modules/monitoring.ts#L16)
diff --git a/docs/interfaces/types.MedusaMiddleware.md b/docs/interfaces/types.MedusaMiddleware.md
index 582bda32..56a547f8 100644
--- a/docs/interfaces/types.MedusaMiddleware.md
+++ b/docs/interfaces/types.MedusaMiddleware.md
@@ -33,4 +33,4 @@ Describe a custom middleware instance.
#### Defined in
-[src/types.ts:152](https://github.com/adrien2p/medusa-extender/blob/c2d2cfc/src/types.ts#L152)
+[src/types.ts:152](https://github.com/adrien2p/medusa-extender/blob/575c26f/src/types.ts#L152)
diff --git a/docs/interfaces/types.Type.md b/docs/interfaces/types.Type.md
index 15f90169..130f7988 100644
--- a/docs/interfaces/types.Type.md
+++ b/docs/interfaces/types.Type.md
@@ -40,4 +40,4 @@ Function.constructor
#### Defined in
-[src/types.ts:6](https://github.com/adrien2p/medusa-extender/blob/c2d2cfc/src/types.ts#L6)
+[src/types.ts:6](https://github.com/adrien2p/medusa-extender/blob/575c26f/src/types.ts#L6)
diff --git a/docs/modules.md b/docs/modules.md
index c7496796..b2a85cf1 100644
--- a/docs/modules.md
+++ b/docs/modules.md
@@ -16,15 +16,16 @@
- [event-emmiter](modules/event_emmiter.md)
- [index](modules/index.md)
- [loaders](modules/loaders.md)
-- [loaders/api.loader](modules/loaders_api_loader.md)
+- [loaders/admin-api.loader](modules/loaders_admin_api_loader.md)
- [loaders/database.loader](modules/loaders_database_loader.md)
- [loaders/entities.loader](modules/loaders_entities_loader.md)
-- [loaders/middlewares.loader](modules/loaders_middlewares_loader.md)
+- [loaders/helpers/apply-middlewares](modules/loaders_helpers_apply_middlewares.md)
+- [loaders/helpers/apply-routers](modules/loaders_helpers_apply_routers.md)
- [loaders/migrations.loader](modules/loaders_migrations_loader.md)
- [loaders/plugins.loader](modules/loaders_plugins_loader.md)
- [loaders/repository.loader](modules/loaders_repository_loader.md)
-- [loaders/routes.loader](modules/loaders_routes_loader.md)
- [loaders/services.loader](modules/loaders_services_loader.md)
+- [loaders/store-api.loader](modules/loaders_store_api_loader.md)
- [loaders/validators.loader](modules/loaders_validators_loader.md)
- [metadata-reader](modules/metadata_reader.md)
- [modules/monitoring](modules/modules_monitoring.md)
diff --git a/docs/modules/constants.md b/docs/modules/constants.md
index f866cae8..d7980664 100644
--- a/docs/modules/constants.md
+++ b/docs/modules/constants.md
@@ -20,7 +20,7 @@ Metadata key to store config from decorated injectables.
#### Defined in
-[src/constants.ts:9](https://github.com/adrien2p/medusa-extender/blob/c2d2cfc/src/constants.ts#L9)
+[src/constants.ts:9](https://github.com/adrien2p/medusa-extender/blob/575c26f/src/constants.ts#L9)
___
@@ -66,7 +66,7 @@ Hold the name of the medusa services registered into the container for later on
#### Defined in
-[src/constants.ts:14](https://github.com/adrien2p/medusa-extender/blob/c2d2cfc/src/constants.ts#L14)
+[src/constants.ts:14](https://github.com/adrien2p/medusa-extender/blob/575c26f/src/constants.ts#L14)
___
@@ -78,4 +78,4 @@ Metadata key to store config from decorated injectables.
#### Defined in
-[src/constants.ts:4](https://github.com/adrien2p/medusa-extender/blob/c2d2cfc/src/constants.ts#L4)
+[src/constants.ts:4](https://github.com/adrien2p/medusa-extender/blob/575c26f/src/constants.ts#L4)
diff --git a/docs/modules/decorators_components_decorator.md b/docs/modules/decorators_components_decorator.md
index b4599e23..f152956e 100644
--- a/docs/modules/decorators_components_decorator.md
+++ b/docs/modules/decorators_components_decorator.md
@@ -40,7 +40,7 @@ Mark a class as an entity to be used by the loader.
#### Defined in
-[src/decorators/components.decorator.ts:16](https://github.com/adrien2p/medusa-extender/blob/c2d2cfc/src/decorators/components.decorator.ts#L16)
+[src/decorators/components.decorator.ts:16](https://github.com/adrien2p/medusa-extender/blob/575c26f/src/decorators/components.decorator.ts#L16)
___
@@ -62,7 +62,7 @@ Mark a class as a middleware to be used by the loader.
#### Defined in
-[src/decorators/components.decorator.ts:43](https://github.com/adrien2p/medusa-extender/blob/c2d2cfc/src/decorators/components.decorator.ts#L43)
+[src/decorators/components.decorator.ts:43](https://github.com/adrien2p/medusa-extender/blob/575c26f/src/decorators/components.decorator.ts#L43)
___
@@ -78,7 +78,7 @@ Mark a class as a migration to be used by the loader.
#### Defined in
-[src/decorators/components.decorator.ts:51](https://github.com/adrien2p/medusa-extender/blob/c2d2cfc/src/decorators/components.decorator.ts#L51)
+[src/decorators/components.decorator.ts:51](https://github.com/adrien2p/medusa-extender/blob/575c26f/src/decorators/components.decorator.ts#L51)
___
@@ -106,7 +106,7 @@ Mark a class as a repository to be used by the loader.
#### Defined in
-[src/decorators/components.decorator.ts:34](https://github.com/adrien2p/medusa-extender/blob/c2d2cfc/src/decorators/components.decorator.ts#L34)
+[src/decorators/components.decorator.ts:34](https://github.com/adrien2p/medusa-extender/blob/575c26f/src/decorators/components.decorator.ts#L34)
___
@@ -128,7 +128,7 @@ Mark a class as a router to be used by the loader.
#### Defined in
-[src/decorators/components.decorator.ts:60](https://github.com/adrien2p/medusa-extender/blob/c2d2cfc/src/decorators/components.decorator.ts#L60)
+[src/decorators/components.decorator.ts:60](https://github.com/adrien2p/medusa-extender/blob/575c26f/src/decorators/components.decorator.ts#L60)
___
@@ -156,7 +156,7 @@ Mark a class as a service to be used by the loader.
#### Defined in
-[src/decorators/components.decorator.ts:25](https://github.com/adrien2p/medusa-extender/blob/c2d2cfc/src/decorators/components.decorator.ts#L25)
+[src/decorators/components.decorator.ts:25](https://github.com/adrien2p/medusa-extender/blob/575c26f/src/decorators/components.decorator.ts#L25)
___
@@ -178,4 +178,4 @@ Mark a class as a validator to be used by the validator utility.
#### Defined in
-[src/decorators/components.decorator.ts:69](https://github.com/adrien2p/medusa-extender/blob/c2d2cfc/src/decorators/components.decorator.ts#L69)
+[src/decorators/components.decorator.ts:69](https://github.com/adrien2p/medusa-extender/blob/575c26f/src/decorators/components.decorator.ts#L69)
diff --git a/docs/modules/decorators_module_decorator.md b/docs/modules/decorators_module_decorator.md
index b4666d5b..365193b1 100644
--- a/docs/modules/decorators_module_decorator.md
+++ b/docs/modules/decorators_module_decorator.md
@@ -29,4 +29,4 @@ Mark a class as aa module and store all injectable on it.
#### Defined in
-[src/decorators/module.decorator.ts:9](https://github.com/adrien2p/medusa-extender/blob/c2d2cfc/src/decorators/module.decorator.ts#L9)
+[src/decorators/module.decorator.ts:9](https://github.com/adrien2p/medusa-extender/blob/575c26f/src/decorators/module.decorator.ts#L9)
diff --git a/docs/modules/decorators_onMedusaEntityEvent_decorator.md b/docs/modules/decorators_onMedusaEntityEvent_decorator.md
index db2f98c7..c7c3e64b 100644
--- a/docs/modules/decorators_onMedusaEntityEvent_decorator.md
+++ b/docs/modules/decorators_onMedusaEntityEvent_decorator.md
@@ -24,7 +24,7 @@
#### Defined in
-[src/decorators/onMedusaEntityEvent.decorator.ts:11](https://github.com/adrien2p/medusa-extender/blob/c2d2cfc/src/decorators/onMedusaEntityEvent.decorator.ts#L11)
+[src/decorators/onMedusaEntityEvent.decorator.ts:11](https://github.com/adrien2p/medusa-extender/blob/575c26f/src/decorators/onMedusaEntityEvent.decorator.ts#L11)
___
@@ -41,7 +41,7 @@ ___
#### Defined in
-[src/decorators/onMedusaEntityEvent.decorator.ts:6](https://github.com/adrien2p/medusa-extender/blob/c2d2cfc/src/decorators/onMedusaEntityEvent.decorator.ts#L6)
+[src/decorators/onMedusaEntityEvent.decorator.ts:6](https://github.com/adrien2p/medusa-extender/blob/575c26f/src/decorators/onMedusaEntityEvent.decorator.ts#L6)
___
@@ -60,7 +60,7 @@ Event types that can be emitted.
#### Defined in
-[src/decorators/onMedusaEntityEvent.decorator.ts:16](https://github.com/adrien2p/medusa-extender/blob/c2d2cfc/src/decorators/onMedusaEntityEvent.decorator.ts#L16)
+[src/decorators/onMedusaEntityEvent.decorator.ts:16](https://github.com/adrien2p/medusa-extender/blob/575c26f/src/decorators/onMedusaEntityEvent.decorator.ts#L16)
___
@@ -86,7 +86,7 @@ The arguments expected by the [OnMedusaEntityEvent](../classes/decorators_onMedu
#### Defined in
-[src/decorators/onMedusaEntityEvent.decorator.ts:25](https://github.com/adrien2p/medusa-extender/blob/c2d2cfc/src/decorators/onMedusaEntityEvent.decorator.ts#L25)
+[src/decorators/onMedusaEntityEvent.decorator.ts:25](https://github.com/adrien2p/medusa-extender/blob/575c26f/src/decorators/onMedusaEntityEvent.decorator.ts#L25)
___
@@ -112,4 +112,4 @@ The arguments expected by the event handler.
#### Defined in
-[src/decorators/onMedusaEntityEvent.decorator.ts:33](https://github.com/adrien2p/medusa-extender/blob/c2d2cfc/src/decorators/onMedusaEntityEvent.decorator.ts#L33)
+[src/decorators/onMedusaEntityEvent.decorator.ts:33](https://github.com/adrien2p/medusa-extender/blob/575c26f/src/decorators/onMedusaEntityEvent.decorator.ts#L33)
diff --git a/docs/modules/decorators_utils.md b/docs/modules/decorators_utils.md
index 136dead6..a3531d3f 100644
--- a/docs/modules/decorators_utils.md
+++ b/docs/modules/decorators_utils.md
@@ -32,4 +32,4 @@
#### Defined in
-[src/decorators/utils.ts:4](https://github.com/adrien2p/medusa-extender/blob/c2d2cfc/src/decorators/utils.ts#L4)
+[src/decorators/utils.ts:4](https://github.com/adrien2p/medusa-extender/blob/575c26f/src/decorators/utils.ts#L4)
diff --git a/docs/modules/event_emmiter.Internals.md b/docs/modules/event_emmiter.Internals.md
index 8ec3fd1d..30875105 100644
--- a/docs/modules/event_emmiter.Internals.md
+++ b/docs/modules/event_emmiter.Internals.md
@@ -38,4 +38,4 @@ A listener descriptor.
#### Defined in
-[src/event-emmiter.ts:9](https://github.com/adrien2p/medusa-extender/blob/c2d2cfc/src/event-emmiter.ts#L9)
+[src/event-emmiter.ts:9](https://github.com/adrien2p/medusa-extender/blob/575c26f/src/event-emmiter.ts#L9)
diff --git a/docs/modules/event_emmiter.md b/docs/modules/event_emmiter.md
index 3f725d5a..c1fa5938 100644
--- a/docs/modules/event_emmiter.md
+++ b/docs/modules/event_emmiter.md
@@ -23,4 +23,4 @@ Export the instance of the event emmiter.
#### Defined in
-[src/event-emmiter.ts:102](https://github.com/adrien2p/medusa-extender/blob/c2d2cfc/src/event-emmiter.ts#L102)
+[src/event-emmiter.ts:102](https://github.com/adrien2p/medusa-extender/blob/575c26f/src/event-emmiter.ts#L102)
diff --git a/docs/modules/index.md b/docs/modules/index.md
index f8029479..0c716dad 100644
--- a/docs/modules/index.md
+++ b/docs/modules/index.md
@@ -292,4 +292,4 @@ Renames and re-exports [customEventEmitter](event_emmiter.md#customeventemitter)
#### Defined in
-[src/index.ts:27](https://github.com/adrien2p/medusa-extender/blob/c2d2cfc/src/index.ts#L27)
+[src/index.ts:27](https://github.com/adrien2p/medusa-extender/blob/575c26f/src/index.ts#L27)
diff --git a/docs/modules/loaders.md b/docs/modules/loaders.md
index 4e06871a..40f2a680 100644
--- a/docs/modules/loaders.md
+++ b/docs/modules/loaders.md
@@ -26,8 +26,7 @@
- [Type](loaders.md#type)
- [Utils](loaders.md#utils)
- [ValidatorInjectionOptions](loaders.md#validatorinjectionoptions)
-- [apiLoader](loaders.md#apiloader)
-- [authenticatedRoutesLoader](loaders.md#authenticatedroutesloader)
+- [adminApiLoader](loaders.md#adminapiloader)
- [databaseLoader](loaders.md#databaseloader)
- [entitiesLoader](loaders.md#entitiesloader)
- [migrationsLoader](loaders.md#migrationsloader)
@@ -42,7 +41,7 @@
- [registerService](loaders.md#registerservice)
- [repositoriesLoader](loaders.md#repositoriesloader)
- [servicesLoader](loaders.md#servicesloader)
-- [unauthenticatedRoutesLoader](loaders.md#unauthenticatedroutesloader)
+- [storeApiLoader](loaders.md#storeapiloader)
- [validatorsLoader](loaders.md#validatorsloader)
## References
@@ -167,15 +166,9 @@ Re-exports [ValidatorInjectionOptions](types.md#validatorinjectionoptions)
___
-### apiLoader
+### adminApiLoader
-Re-exports [apiLoader](loaders_api_loader.md#apiloader)
-
-___
-
-### authenticatedRoutesLoader
-
-Re-exports [authenticatedRoutesLoader](loaders_routes_loader.md#authenticatedroutesloader)
+Re-exports [adminApiLoader](loaders_admin_api_loader.md#adminapiloader)
___
@@ -263,9 +256,9 @@ Re-exports [servicesLoader](loaders_services_loader.md#servicesloader)
___
-### unauthenticatedRoutesLoader
+### storeApiLoader
-Re-exports [unauthenticatedRoutesLoader](loaders_routes_loader.md#unauthenticatedroutesloader)
+Re-exports [storeApiLoader](loaders_store_api_loader.md#storeapiloader)
___
diff --git a/docs/modules/loaders_admin_api_loader.md b/docs/modules/loaders_admin_api_loader.md
new file mode 100644
index 00000000..bc717f42
--- /dev/null
+++ b/docs/modules/loaders_admin_api_loader.md
@@ -0,0 +1,34 @@
+[medusa-extender](../README.md) / [Exports](../modules.md) / loaders/admin-api.loader
+
+# Module: loaders/admin-api.loader
+
+## Table of contents
+
+### Functions
+
+- [adminApiLoader](loaders_admin_api_loader.md#adminapiloader)
+
+## Functions
+
+### adminApiLoader
+
+▸ **adminApiLoader**(`app`, `middlewares`, `routers`): `Promise`<`void`\>
+
+**`internal`**
+Apply middlewares and routes on admin API.
+
+#### Parameters
+
+| Name | Type |
+| :------ | :------ |
+| `app` | `Router` |
+| `middlewares` | [`GetInjectableOptions`](types.md#getinjectableoptions)<``"middleware"``\> |
+| `routers` | [`GetInjectableOptions`](types.md#getinjectableoptions)<``"router"``\> |
+
+#### Returns
+
+`Promise`<`void`\>
+
+#### Defined in
+
+[src/loaders/admin-api.loader.ts:13](https://github.com/adrien2p/medusa-extender/blob/575c26f/src/loaders/admin-api.loader.ts#L13)
diff --git a/docs/modules/loaders_api_loader.md b/docs/modules/loaders_api_loader.md
deleted file mode 100644
index b6b46f58..00000000
--- a/docs/modules/loaders_api_loader.md
+++ /dev/null
@@ -1,33 +0,0 @@
-[medusa-extender](../README.md) / [Exports](../modules.md) / loaders/api.loader
-
-# Module: loaders/api.loader
-
-## Table of contents
-
-### Functions
-
-- [apiLoader](loaders_api_loader.md#apiloader)
-
-## Functions
-
-### apiLoader
-
-▸ **apiLoader**(`app`, `middlewares`): `Promise`<`void`\>
-
-**`internal`**
-Decorate the original api loader to apply our custom middleware first.
-
-#### Parameters
-
-| Name | Type |
-| :------ | :------ |
-| `app` | `Express` |
-| `middlewares` | [`GetInjectableOptions`](types.md#getinjectableoptions)<``"middleware"``\> |
-
-#### Returns
-
-`Promise`<`void`\>
-
-#### Defined in
-
-[src/loaders/api.loader.ts:12](https://github.com/adrien2p/medusa-extender/blob/c2d2cfc/src/loaders/api.loader.ts#L12)
diff --git a/docs/modules/loaders_database_loader.md b/docs/modules/loaders_database_loader.md
index 37144c8a..c861674a 100644
--- a/docs/modules/loaders_database_loader.md
+++ b/docs/modules/loaders_database_loader.md
@@ -27,4 +27,4 @@
#### Defined in
-[src/loaders/database.loader.ts:5](https://github.com/adrien2p/medusa-extender/blob/c2d2cfc/src/loaders/database.loader.ts#L5)
+[src/loaders/database.loader.ts:5](https://github.com/adrien2p/medusa-extender/blob/575c26f/src/loaders/database.loader.ts#L5)
diff --git a/docs/modules/loaders_entities_loader.md b/docs/modules/loaders_entities_loader.md
index f0e909f3..27272a2b 100644
--- a/docs/modules/loaders_entities_loader.md
+++ b/docs/modules/loaders_entities_loader.md
@@ -30,7 +30,7 @@
#### Defined in
-[src/loaders/entities.loader.ts:5](https://github.com/adrien2p/medusa-extender/blob/c2d2cfc/src/loaders/entities.loader.ts#L5)
+[src/loaders/entities.loader.ts:5](https://github.com/adrien2p/medusa-extender/blob/575c26f/src/loaders/entities.loader.ts#L5)
___
@@ -50,7 +50,7 @@ ___
#### Defined in
-[src/loaders/entities.loader.ts:16](https://github.com/adrien2p/medusa-extender/blob/c2d2cfc/src/loaders/entities.loader.ts#L16)
+[src/loaders/entities.loader.ts:16](https://github.com/adrien2p/medusa-extender/blob/575c26f/src/loaders/entities.loader.ts#L16)
___
@@ -73,7 +73,7 @@ Load custom entity and override existing ones.
#### Defined in
-[src/loaders/entities.loader.ts:49](https://github.com/adrien2p/medusa-extender/blob/c2d2cfc/src/loaders/entities.loader.ts#L49)
+[src/loaders/entities.loader.ts:49](https://github.com/adrien2p/medusa-extender/blob/575c26f/src/loaders/entities.loader.ts#L49)
___
@@ -97,4 +97,4 @@ Load custom entity into the container.
#### Defined in
-[src/loaders/entities.loader.ts:30](https://github.com/adrien2p/medusa-extender/blob/c2d2cfc/src/loaders/entities.loader.ts#L30)
+[src/loaders/entities.loader.ts:30](https://github.com/adrien2p/medusa-extender/blob/575c26f/src/loaders/entities.loader.ts#L30)
diff --git a/docs/modules/loaders_helpers_apply_middlewares.md b/docs/modules/loaders_helpers_apply_middlewares.md
new file mode 100644
index 00000000..213d4c1a
--- /dev/null
+++ b/docs/modules/loaders_helpers_apply_middlewares.md
@@ -0,0 +1,52 @@
+[medusa-extender](../README.md) / [Exports](../modules.md) / loaders/helpers/apply-middlewares
+
+# Module: loaders/helpers/apply-middlewares
+
+## Table of contents
+
+### Functions
+
+- [applyAfterAuthMiddleware](loaders_helpers_apply_middlewares.md#applyafterauthmiddleware)
+- [applyBeforeAuthMiddleware](loaders_helpers_apply_middlewares.md#applybeforeauthmiddleware)
+
+## Functions
+
+### applyAfterAuthMiddleware
+
+▸ **applyAfterAuthMiddleware**(`app`, `middlewares`): `void`
+
+#### Parameters
+
+| Name | Type |
+| :------ | :------ |
+| `app` | `Router` |
+| `middlewares` | [`GetInjectableOptions`](types.md#getinjectableoptions)<``"middleware"``\> |
+
+#### Returns
+
+`void`
+
+#### Defined in
+
+[src/loaders/helpers/apply-middlewares.ts:18](https://github.com/adrien2p/medusa-extender/blob/575c26f/src/loaders/helpers/apply-middlewares.ts#L18)
+
+___
+
+### applyBeforeAuthMiddleware
+
+▸ **applyBeforeAuthMiddleware**(`app`, `middlewares`): `void`
+
+#### Parameters
+
+| Name | Type |
+| :------ | :------ |
+| `app` | `Router` |
+| `middlewares` | [`GetInjectableOptions`](types.md#getinjectableoptions)<``"middleware"``\> |
+
+#### Returns
+
+`void`
+
+#### Defined in
+
+[src/loaders/helpers/apply-middlewares.ts:5](https://github.com/adrien2p/medusa-extender/blob/575c26f/src/loaders/helpers/apply-middlewares.ts#L5)
diff --git a/docs/modules/loaders_helpers_apply_routers.md b/docs/modules/loaders_helpers_apply_routers.md
new file mode 100644
index 00000000..57dcda7b
--- /dev/null
+++ b/docs/modules/loaders_helpers_apply_routers.md
@@ -0,0 +1,52 @@
+[medusa-extender](../README.md) / [Exports](../modules.md) / loaders/helpers/apply-routers
+
+# Module: loaders/helpers/apply-routers
+
+## Table of contents
+
+### Functions
+
+- [applyAfterAuthRouters](loaders_helpers_apply_routers.md#applyafterauthrouters)
+- [applyBeforeAuthRouters](loaders_helpers_apply_routers.md#applybeforeauthrouters)
+
+## Functions
+
+### applyAfterAuthRouters
+
+▸ **applyAfterAuthRouters**(`app`, `routesOptions`): `void`
+
+#### Parameters
+
+| Name | Type |
+| :------ | :------ |
+| `app` | `Router` |
+| `routesOptions` | [`GetInjectableOptions`](types.md#getinjectableoptions)<``"router"``\> |
+
+#### Returns
+
+`void`
+
+#### Defined in
+
+[src/loaders/helpers/apply-routers.ts:14](https://github.com/adrien2p/medusa-extender/blob/575c26f/src/loaders/helpers/apply-routers.ts#L14)
+
+___
+
+### applyBeforeAuthRouters
+
+▸ **applyBeforeAuthRouters**(`app`, `routesOptions`): `void`
+
+#### Parameters
+
+| Name | Type |
+| :------ | :------ |
+| `app` | `Router` |
+| `routesOptions` | [`GetInjectableOptions`](types.md#getinjectableoptions)<``"router"``\> |
+
+#### Returns
+
+`void`
+
+#### Defined in
+
+[src/loaders/helpers/apply-routers.ts:4](https://github.com/adrien2p/medusa-extender/blob/575c26f/src/loaders/helpers/apply-routers.ts#L4)
diff --git a/docs/modules/loaders_middlewares_loader.md b/docs/modules/loaders_middlewares_loader.md
deleted file mode 100644
index dd6ed688..00000000
--- a/docs/modules/loaders_middlewares_loader.md
+++ /dev/null
@@ -1,80 +0,0 @@
-[medusa-extender](../README.md) / [Exports](../modules.md) / loaders/middlewares.loader
-
-# Module: loaders/middlewares.loader
-
-## Table of contents
-
-### Functions
-
-- [middlewaresLoader](loaders_middlewares_loader.md#middlewaresloader)
-- [wrapMiddleware](loaders_middlewares_loader.md#wrapmiddleware)
-
-## Functions
-
-### middlewaresLoader
-
-▸ **middlewaresLoader**(`app`, `container`, `middlewares`): `void`
-
-**`internal`**
-Register custom middlewares into medusa middleware service to be applied at the right moment.
-
-#### Parameters
-
-| Name | Type |
-| :------ | :------ |
-| `app` | `Express` |
-| `container` | `AwilixContainer`<`any`\> |
-| `middlewares` | [`GetInjectableOptions`](types.md#getinjectableoptions)<``"middleware"``\> |
-
-#### Returns
-
-`void`
-
-#### Defined in
-
-[src/loaders/middlewares.loader.ts:13](https://github.com/adrien2p/medusa-extender/blob/c2d2cfc/src/loaders/middlewares.loader.ts#L13)
-
-___
-
-### wrapMiddleware
-
-▸ **wrapMiddleware**(`middleware`): (`{ app }`: { `app`: `Express` }) => (...`args`: `unknown`[]) => `void`
-
-#### Parameters
-
-| Name | Type |
-| :------ | :------ |
-| `middleware` | [`GetInjectableOption`](types.md#getinjectableoption)<``"middleware"``\> |
-
-#### Returns
-
-`fn`
-
-▸ (`{ app }`): (...`args`: `unknown`[]) => `void`
-
-##### Parameters
-
-| Name | Type |
-| :------ | :------ |
-| `{ app }` | `Object` |
-| `{ app }.app` | `Express` |
-
-##### Returns
-
-`fn`
-
-▸ (...`args`): `void`
-
-##### Parameters
-
-| Name | Type |
-| :------ | :------ |
-| `...args` | `unknown`[] |
-
-##### Returns
-
-`void`
-
-#### Defined in
-
-[src/loaders/middlewares.loader.ts:39](https://github.com/adrien2p/medusa-extender/blob/c2d2cfc/src/loaders/middlewares.loader.ts#L39)
diff --git a/docs/modules/loaders_migrations_loader.md b/docs/modules/loaders_migrations_loader.md
index ecc85ffa..a2a652b5 100644
--- a/docs/modules/loaders_migrations_loader.md
+++ b/docs/modules/loaders_migrations_loader.md
@@ -30,4 +30,4 @@ Run custom migrations that are find from the provided directory and stored in a
#### Defined in
-[src/loaders/migrations.loader.ts:10](https://github.com/adrien2p/medusa-extender/blob/c2d2cfc/src/loaders/migrations.loader.ts#L10)
+[src/loaders/migrations.loader.ts:10](https://github.com/adrien2p/medusa-extender/blob/575c26f/src/loaders/migrations.loader.ts#L10)
diff --git a/docs/modules/loaders_plugins_loader.md b/docs/modules/loaders_plugins_loader.md
index 57abef27..93fcbac9 100644
--- a/docs/modules/loaders_plugins_loader.md
+++ b/docs/modules/loaders_plugins_loader.md
@@ -29,4 +29,4 @@ Register all listeners before the plugins are loaded to be sure that the scope m
#### Defined in
-[src/loaders/plugins.loader.ts:11](https://github.com/adrien2p/medusa-extender/blob/c2d2cfc/src/loaders/plugins.loader.ts#L11)
+[src/loaders/plugins.loader.ts:11](https://github.com/adrien2p/medusa-extender/blob/575c26f/src/loaders/plugins.loader.ts#L11)
diff --git a/docs/modules/loaders_repository_loader.md b/docs/modules/loaders_repository_loader.md
index e6dc7f34..35bcee21 100644
--- a/docs/modules/loaders_repository_loader.md
+++ b/docs/modules/loaders_repository_loader.md
@@ -29,7 +29,7 @@
#### Defined in
-[src/loaders/repository.loader.ts:16](https://github.com/adrien2p/medusa-extender/blob/c2d2cfc/src/loaders/repository.loader.ts#L16)
+[src/loaders/repository.loader.ts:16](https://github.com/adrien2p/medusa-extender/blob/575c26f/src/loaders/repository.loader.ts#L16)
___
@@ -52,7 +52,7 @@ Load custom repositories and override existing ones.
#### Defined in
-[src/loaders/repository.loader.ts:48](https://github.com/adrien2p/medusa-extender/blob/c2d2cfc/src/loaders/repository.loader.ts#L48)
+[src/loaders/repository.loader.ts:48](https://github.com/adrien2p/medusa-extender/blob/575c26f/src/loaders/repository.loader.ts#L48)
___
@@ -76,7 +76,7 @@ Load custom repository into the container.
#### Defined in
-[src/loaders/repository.loader.ts:30](https://github.com/adrien2p/medusa-extender/blob/c2d2cfc/src/loaders/repository.loader.ts#L30)
+[src/loaders/repository.loader.ts:30](https://github.com/adrien2p/medusa-extender/blob/575c26f/src/loaders/repository.loader.ts#L30)
___
@@ -97,4 +97,4 @@ ___
#### Defined in
-[src/loaders/repository.loader.ts:5](https://github.com/adrien2p/medusa-extender/blob/c2d2cfc/src/loaders/repository.loader.ts#L5)
+[src/loaders/repository.loader.ts:5](https://github.com/adrien2p/medusa-extender/blob/575c26f/src/loaders/repository.loader.ts#L5)
diff --git a/docs/modules/loaders_routes_loader.md b/docs/modules/loaders_routes_loader.md
deleted file mode 100644
index 6bfff450..00000000
--- a/docs/modules/loaders_routes_loader.md
+++ /dev/null
@@ -1,52 +0,0 @@
-[medusa-extender](../README.md) / [Exports](../modules.md) / loaders/routes.loader
-
-# Module: loaders/routes.loader
-
-## Table of contents
-
-### Functions
-
-- [authenticatedRoutesLoader](loaders_routes_loader.md#authenticatedroutesloader)
-- [unauthenticatedRoutesLoader](loaders_routes_loader.md#unauthenticatedroutesloader)
-
-## Functions
-
-### authenticatedRoutesLoader
-
-▸ **authenticatedRoutesLoader**(`routesOptions`, `app`): `void`
-
-#### Parameters
-
-| Name | Type |
-| :------ | :------ |
-| `routesOptions` | [`GetInjectableOptions`](types.md#getinjectableoptions)<``"router"``\> |
-| `app` | `Express` |
-
-#### Returns
-
-`void`
-
-#### Defined in
-
-[src/loaders/routes.loader.ts:4](https://github.com/adrien2p/medusa-extender/blob/c2d2cfc/src/loaders/routes.loader.ts#L4)
-
-___
-
-### unauthenticatedRoutesLoader
-
-▸ **unauthenticatedRoutesLoader**(`routesOptions`, `app`): `void`
-
-#### Parameters
-
-| Name | Type |
-| :------ | :------ |
-| `routesOptions` | [`GetInjectableOptions`](types.md#getinjectableoptions)<``"router"``\> |
-| `app` | `Express` |
-
-#### Returns
-
-`void`
-
-#### Defined in
-
-[src/loaders/routes.loader.ts:14](https://github.com/adrien2p/medusa-extender/blob/c2d2cfc/src/loaders/routes.loader.ts#L14)
diff --git a/docs/modules/loaders_services_loader.md b/docs/modules/loaders_services_loader.md
index fda4bbec..4388d833 100644
--- a/docs/modules/loaders_services_loader.md
+++ b/docs/modules/loaders_services_loader.md
@@ -33,7 +33,7 @@ Load custom service and override existing ones.
#### Defined in
-[src/loaders/services.loader.ts:55](https://github.com/adrien2p/medusa-extender/blob/c2d2cfc/src/loaders/services.loader.ts#L55)
+[src/loaders/services.loader.ts:55](https://github.com/adrien2p/medusa-extender/blob/575c26f/src/loaders/services.loader.ts#L55)
___
@@ -58,7 +58,7 @@ Load custom service into the container.
#### Defined in
-[src/loaders/services.loader.ts:31](https://github.com/adrien2p/medusa-extender/blob/c2d2cfc/src/loaders/services.loader.ts#L31)
+[src/loaders/services.loader.ts:31](https://github.com/adrien2p/medusa-extender/blob/575c26f/src/loaders/services.loader.ts#L31)
___
@@ -81,4 +81,4 @@ Load custom services from the rootDir.
#### Defined in
-[src/loaders/services.loader.ts:9](https://github.com/adrien2p/medusa-extender/blob/c2d2cfc/src/loaders/services.loader.ts#L9)
+[src/loaders/services.loader.ts:9](https://github.com/adrien2p/medusa-extender/blob/575c26f/src/loaders/services.loader.ts#L9)
diff --git a/docs/modules/loaders_store_api_loader.md b/docs/modules/loaders_store_api_loader.md
new file mode 100644
index 00000000..141e3874
--- /dev/null
+++ b/docs/modules/loaders_store_api_loader.md
@@ -0,0 +1,34 @@
+[medusa-extender](../README.md) / [Exports](../modules.md) / loaders/store-api.loader
+
+# Module: loaders/store-api.loader
+
+## Table of contents
+
+### Functions
+
+- [storeApiLoader](loaders_store_api_loader.md#storeapiloader)
+
+## Functions
+
+### storeApiLoader
+
+▸ **storeApiLoader**(`app`, `middlewares`, `routers`): `Promise`<`void`\>
+
+**`internal`**
+Apply middlewares and routes on store API.
+
+#### Parameters
+
+| Name | Type |
+| :------ | :------ |
+| `app` | `Router` |
+| `middlewares` | [`GetInjectableOptions`](types.md#getinjectableoptions)<``"middleware"``\> |
+| `routers` | [`GetInjectableOptions`](types.md#getinjectableoptions)<``"router"``\> |
+
+#### Returns
+
+`Promise`<`void`\>
+
+#### Defined in
+
+[src/loaders/store-api.loader.ts:13](https://github.com/adrien2p/medusa-extender/blob/575c26f/src/loaders/store-api.loader.ts#L13)
diff --git a/docs/modules/loaders_validators_loader.md b/docs/modules/loaders_validators_loader.md
index 7a753ed2..bf26f704 100644
--- a/docs/modules/loaders_validators_loader.md
+++ b/docs/modules/loaders_validators_loader.md
@@ -26,4 +26,4 @@
#### Defined in
-[src/loaders/validators.loader.ts:4](https://github.com/adrien2p/medusa-extender/blob/c2d2cfc/src/loaders/validators.loader.ts#L4)
+[src/loaders/validators.loader.ts:4](https://github.com/adrien2p/medusa-extender/blob/575c26f/src/loaders/validators.loader.ts#L4)
diff --git a/docs/modules/metadata_reader.md b/docs/modules/metadata_reader.md
index 813a1da2..103b1573 100644
--- a/docs/modules/metadata_reader.md
+++ b/docs/modules/metadata_reader.md
@@ -40,7 +40,7 @@ Return the options from components.
#### Defined in
-[src/metadata-reader.ts:36](https://github.com/adrien2p/medusa-extender/blob/c2d2cfc/src/metadata-reader.ts#L36)
+[src/metadata-reader.ts:36](https://github.com/adrien2p/medusa-extender/blob/575c26f/src/metadata-reader.ts#L36)
___
@@ -62,4 +62,4 @@ Read all metadata from the imported modules and extract components that will be
#### Defined in
-[src/metadata-reader.ts:14](https://github.com/adrien2p/medusa-extender/blob/c2d2cfc/src/metadata-reader.ts#L14)
+[src/metadata-reader.ts:14](https://github.com/adrien2p/medusa-extender/blob/575c26f/src/metadata-reader.ts#L14)
diff --git a/docs/modules/modules_monitoring.md b/docs/modules/modules_monitoring.md
index ffdf752b..da623da8 100644
--- a/docs/modules/modules_monitoring.md
+++ b/docs/modules/modules_monitoring.md
@@ -31,4 +31,4 @@
#### Defined in
-[src/modules/monitoring.ts:23](https://github.com/adrien2p/medusa-extender/blob/c2d2cfc/src/modules/monitoring.ts#L23)
+[src/modules/monitoring.ts:23](https://github.com/adrien2p/medusa-extender/blob/575c26f/src/modules/monitoring.ts#L23)
diff --git a/docs/modules/types.md b/docs/modules/types.md
index e3f002c3..6172464d 100644
--- a/docs/modules/types.md
+++ b/docs/modules/types.md
@@ -53,7 +53,7 @@
#### Defined in
-[src/types.ts:9](https://github.com/adrien2p/medusa-extender/blob/c2d2cfc/src/types.ts#L9)
+[src/types.ts:9](https://github.com/adrien2p/medusa-extender/blob/575c26f/src/types.ts#L9)
___
@@ -78,7 +78,7 @@ Defines the injection options for entities.
#### Defined in
-[src/types.ts:26](https://github.com/adrien2p/medusa-extender/blob/c2d2cfc/src/types.ts#L26)
+[src/types.ts:26](https://github.com/adrien2p/medusa-extender/blob/575c26f/src/types.ts#L26)
___
@@ -96,7 +96,7 @@ Determine which options type it actually is depending on the component type.
#### Defined in
-[src/types.ts:94](https://github.com/adrien2p/medusa-extender/blob/c2d2cfc/src/types.ts#L94)
+[src/types.ts:94](https://github.com/adrien2p/medusa-extender/blob/575c26f/src/types.ts#L94)
___
@@ -114,7 +114,7 @@ Determine which options type it actually is depending on the component type.
#### Defined in
-[src/types.ts:117](https://github.com/adrien2p/medusa-extender/blob/c2d2cfc/src/types.ts#L117)
+[src/types.ts:117](https://github.com/adrien2p/medusa-extender/blob/575c26f/src/types.ts#L117)
___
@@ -126,7 +126,7 @@ Components that does not required any other options that Type.
#### Defined in
-[src/types.ts:14](https://github.com/adrien2p/medusa-extender/blob/c2d2cfc/src/types.ts#L14)
+[src/types.ts:14](https://github.com/adrien2p/medusa-extender/blob/575c26f/src/types.ts#L14)
___
@@ -144,7 +144,7 @@ Union of all options type possible for injectable.
#### Defined in
-[src/types.ts:83](https://github.com/adrien2p/medusa-extender/blob/c2d2cfc/src/types.ts#L83)
+[src/types.ts:83](https://github.com/adrien2p/medusa-extender/blob/575c26f/src/types.ts#L83)
___
@@ -156,7 +156,7 @@ Describe the expected request from a middleware [MedusaMiddleware](../interfaces
#### Defined in
-[src/types.ts:130](https://github.com/adrien2p/medusa-extender/blob/c2d2cfc/src/types.ts#L130)
+[src/types.ts:130](https://github.com/adrien2p/medusa-extender/blob/575c26f/src/types.ts#L130)
___
@@ -175,7 +175,7 @@ Medusa request extended.
#### Defined in
-[src/types.ts:123](https://github.com/adrien2p/medusa-extender/blob/c2d2cfc/src/types.ts#L123)
+[src/types.ts:123](https://github.com/adrien2p/medusa-extender/blob/575c26f/src/types.ts#L123)
___
@@ -185,7 +185,7 @@ ___
#### Defined in
-[src/types.ts:137](https://github.com/adrien2p/medusa-extender/blob/c2d2cfc/src/types.ts#L137)
+[src/types.ts:137](https://github.com/adrien2p/medusa-extender/blob/575c26f/src/types.ts#L137)
___
@@ -204,7 +204,7 @@ Describe all the available options for the Route [MedusaMiddleware](../interface
#### Defined in
-[src/types.ts:142](https://github.com/adrien2p/medusa-extender/blob/c2d2cfc/src/types.ts#L142)
+[src/types.ts:142](https://github.com/adrien2p/medusa-extender/blob/575c26f/src/types.ts#L142)
___
@@ -223,7 +223,7 @@ Defines the injection options for middlewares.
#### Defined in
-[src/types.ts:68](https://github.com/adrien2p/medusa-extender/blob/c2d2cfc/src/types.ts#L68)
+[src/types.ts:68](https://github.com/adrien2p/medusa-extender/blob/575c26f/src/types.ts#L68)
___
@@ -242,7 +242,7 @@ Mix the return type of two objects.
#### Defined in
-[src/types.ts:158](https://github.com/adrien2p/medusa-extender/blob/c2d2cfc/src/types.ts#L158)
+[src/types.ts:158](https://github.com/adrien2p/medusa-extender/blob/575c26f/src/types.ts#L158)
___
@@ -267,7 +267,7 @@ Defines the injection options for services, entities, repositories.
#### Defined in
-[src/types.ts:43](https://github.com/adrien2p/medusa-extender/blob/c2d2cfc/src/types.ts#L43)
+[src/types.ts:43](https://github.com/adrien2p/medusa-extender/blob/575c26f/src/types.ts#L43)
___
@@ -285,7 +285,7 @@ Defines the injection options for routes.
#### Defined in
-[src/types.ts:61](https://github.com/adrien2p/medusa-extender/blob/c2d2cfc/src/types.ts#L61)
+[src/types.ts:61](https://github.com/adrien2p/medusa-extender/blob/575c26f/src/types.ts#L61)
___
@@ -306,7 +306,7 @@ Define a router and its configuration.
#### Defined in
-[src/types.ts:51](https://github.com/adrien2p/medusa-extender/blob/c2d2cfc/src/types.ts#L51)
+[src/types.ts:51](https://github.com/adrien2p/medusa-extender/blob/575c26f/src/types.ts#L51)
___
@@ -332,7 +332,7 @@ Defines the injection options for service.
#### Defined in
-[src/types.ts:34](https://github.com/adrien2p/medusa-extender/blob/c2d2cfc/src/types.ts#L34)
+[src/types.ts:34](https://github.com/adrien2p/medusa-extender/blob/575c26f/src/types.ts#L34)
___
@@ -352,8 +352,8 @@ Defines the injection options for routes.
| Name | Type |
| :------ | :------ |
-| `override?` | [`Type`](../interfaces/types.Type.md)<`TOverride`\> |
+| `override` | [`Type`](../interfaces/types.Type.md)<`TOverride`\> |
#### Defined in
-[src/types.ts:76](https://github.com/adrien2p/medusa-extender/blob/c2d2cfc/src/types.ts#L76)
+[src/types.ts:76](https://github.com/adrien2p/medusa-extender/blob/575c26f/src/types.ts#L76)
diff --git a/package-lock.json b/package-lock.json
index 71890423..d09e5a4a 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -5752,6 +5752,11 @@
}
}
},
+ "express-list-endpoints": {
+ "version": "6.0.0",
+ "resolved": "https://registry.npmjs.org/express-list-endpoints/-/express-list-endpoints-6.0.0.tgz",
+ "integrity": "sha512-1I30bSVego+AU/eSsX/bV2xrOXW5tFhsuXZp7wZd9396bAAxH7KHaAwLXQYra0Aw33xA67HmNiceGf2SOvXaLg=="
+ },
"express-session": {
"version": "1.17.2",
"resolved": "https://registry.npmjs.org/express-session/-/express-session-1.17.2.tgz",
diff --git a/package.json b/package.json
index b3985821..f426b7a5 100644
--- a/package.json
+++ b/package.json
@@ -43,7 +43,7 @@
"build:graph": "./node_modules/.bin/ts_dependency_graph --filter 'types.ts' --filter '**/tests/**' --base_path ./src --max_depth 4 --start ./src/index.ts | dot -T jpeg > ./assets/medusa-extender.jpeg",
"serve:doc": "./node_modules/.bin/docsify serve docs",
"test": "NODE_ENV=test ./node_modules/.bin/jest --collect-coverage --config ./jest.config.js && npm run coverage:badges",
- "coverage:badges": "./node_modules/.bin/jest-coverage-badges --output coverage-bages",
+ "coverage:badges": "./node_modules/.bin/jest-coverage-badges --output coverage-badges",
"release": "standard-version",
"release:minor": "standard-version --release-as minor",
"release:patch": "standard-version --release-as patch",
@@ -51,10 +51,11 @@
},
"dependencies": {
"chalk": "^4.1.2",
+ "express-list-endpoints": "^6.0.0",
"openapi-types": "^10.0.0",
+ "prom-client": "^12.0.0",
"swagger-parser": "^10.0.3",
"swagger-stats": "^0.99.2",
- "prom-client": "^12.0.0",
"webpack": "^5.0.0"
},
"peerDependencies": {
diff --git a/src/Medusa.ts b/src/Medusa.ts
index 5fd745d8..f311f406 100644
--- a/src/Medusa.ts
+++ b/src/Medusa.ts
@@ -6,15 +6,14 @@ import { Constructor } from './types';
import { Utils } from './utils';
import { metadataReader } from './metadata-reader';
import {
- apiLoader,
- authenticatedRoutesLoader,
+ adminApiLoader,
databaseLoader,
migrationsLoader,
overrideEntitiesLoader,
overrideRepositoriesLoader,
pluginsLoadersAndListeners,
servicesLoader,
- unauthenticatedRoutesLoader,
+ storeApiLoader,
validatorsLoader,
} from './loaders';
import { buildMonitoringMiddleware, MonitoringOptions } from './modules/monitoring';
@@ -51,25 +50,32 @@ export class Medusa {
await validatorsLoader(moduleComponentsOptions.get('validator') ?? []);
await overrideEntitiesLoader(moduleComponentsOptions.get('entity') ?? []);
await overrideRepositoriesLoader(moduleComponentsOptions.get('repository') ?? []);
- await apiLoader(this.#express, moduleComponentsOptions.get('middleware') ?? []);
+ await adminApiLoader(
+ this.#express,
+ moduleComponentsOptions.get('middleware') ?? [],
+ moduleComponentsOptions.get('router') ?? []
+ );
+ await storeApiLoader(
+ this.#express,
+ moduleComponentsOptions.get('middleware') ?? [],
+ moduleComponentsOptions.get('router') ?? []
+ );
await databaseLoader(
moduleComponentsOptions.get('entity') ?? [],
moduleComponentsOptions.get('repository') ?? []
);
await pluginsLoadersAndListeners(this.#express);
await servicesLoader(moduleComponentsOptions.get('service') ?? []);
- unauthenticatedRoutesLoader(moduleComponentsOptions.get('router') ?? [], this.#express);
- const { app, container, dbConnection } = await loaders({
+ const { container, dbConnection } = await loaders({
directory: this.#rootDir,
expressApp: this.#express,
});
- authenticatedRoutesLoader(moduleComponentsOptions.get('router') ?? [], app);
-
await migrationsLoader(moduleComponentsOptions.get('migration') ?? [], dbConnection);
- Utils.logRoutes(app);
+ Utils.hydrateRouteLog(this.#express);
+ Utils.displayLogs();
return container as unknown as AwilixContainer;
}
@@ -78,9 +84,12 @@ export class Medusa {
configModule: { monitoring: MonitoringOptions };
};
if (configModule.monitoring) {
- Utils.log('Monitoring module', 'Loading monitoring module with the configuration found in medusa-config');
+ Utils.hydrateLog(
+ 'Monitoring module',
+ 'Loading monitoring module with the configuration found in medusa-config'
+ );
await buildMonitoringMiddleware(this.#express, configModule.monitoring);
- Utils.log('Monitoring module', 'Monitoring module successfully attached');
+ Utils.hydrateLog('Monitoring module', 'Monitoring module successfully attached');
}
}
}
diff --git a/src/loaders/admin-api.loader.ts b/src/loaders/admin-api.loader.ts
new file mode 100644
index 00000000..3ddb45f0
--- /dev/null
+++ b/src/loaders/admin-api.loader.ts
@@ -0,0 +1,59 @@
+import { Router } from 'express';
+import { GetInjectableOptions } from './';
+import { applyAfterAuthMiddleware, applyBeforeAuthMiddleware } from './helpers/apply-middlewares';
+import { applyAfterAuthRouters, applyBeforeAuthRouters } from './helpers/apply-routers';
+
+/**
+ * @internal
+ * Apply middlewares and routes on admin API.
+ * @param app
+ * @param middlewares
+ * @param routers
+ */
+export async function adminApiLoader(
+ app: Router,
+ middlewares: GetInjectableOptions<'middleware'>,
+ routers: GetInjectableOptions<'router'>
+) {
+ const adminMiddlewares = middlewares
+ .map((middleware) => ({
+ ...middleware,
+ routes: middleware.routes.filter((route) => {
+ if (route.path.startsWith('/admin')) {
+ route.path = route.path.replace('/admin', '');
+ return true;
+ }
+ return false;
+ }),
+ }))
+ .filter((middleware) => middleware.routes.length);
+
+ const adminRouters = routers
+ .map((router) => ({
+ ...router,
+ routes: router.routes.filter((route) => {
+ if (route.path.startsWith('/admin')) {
+ route.path = route.path.replace('/admin', '');
+ return true;
+ }
+ return false;
+ }),
+ }))
+ .filter((route) => route.routes.length);
+
+ const adminAuthRouteLoader = await import('@medusajs/medusa/dist/api/routes/admin/auth');
+ const originalAdminAuthRouteLoader = adminAuthRouteLoader.default;
+ adminAuthRouteLoader.default = (app: Router): void => {
+ applyBeforeAuthMiddleware(app, adminMiddlewares);
+ applyBeforeAuthRouters(app, adminRouters);
+ originalAdminAuthRouteLoader(app);
+ };
+
+ const adminAppRouteLoader = await import('@medusajs/medusa/dist/api/routes/admin/apps');
+ const originalAdminAppRouteLoader = adminAppRouteLoader.default;
+ adminAppRouteLoader.default = (app: Router): void => {
+ applyAfterAuthMiddleware(app, adminMiddlewares);
+ applyAfterAuthRouters(app, adminRouters);
+ originalAdminAppRouteLoader(app);
+ };
+}
diff --git a/src/loaders/api.loader.ts b/src/loaders/api.loader.ts
deleted file mode 100644
index d21625e2..00000000
--- a/src/loaders/api.loader.ts
+++ /dev/null
@@ -1,19 +0,0 @@
-import { middlewaresLoader } from './middlewares.loader';
-import { Express } from 'express';
-import { AwilixContainer } from 'awilix';
-import { GetInjectableOptions } from './';
-
-/**
- * @internal
- * Decorate the original api loader to apply our custom middleware first.
- * @param app
- * @param middlewares
- */
-export async function apiLoader(app: Express, middlewares: GetInjectableOptions<'middleware'>): Promise {
- const apiLoader = await import('@medusajs/medusa/dist/loaders/api');
- const originalApiLoader = apiLoader.default;
- apiLoader.default = async (cradle: { app: Express; rootDirectory: string; container: AwilixContainer }) => {
- middlewaresLoader(app, cradle.container, middlewares);
- return originalApiLoader(cradle);
- };
-}
diff --git a/src/loaders/entities.loader.ts b/src/loaders/entities.loader.ts
index 25b7842f..8f10c20b 100644
--- a/src/loaders/entities.loader.ts
+++ b/src/loaders/entities.loader.ts
@@ -38,7 +38,7 @@ export function registerEntity(container: AwilixContainer, entityOptions: GetInj
(container as any).registerAdd('db_entities', asValue(entity));
- Utils.log('MedusaLoader#entitiesLoader', `Entity registered - ${resolutionKey}`);
+ Utils.hydrateLog('MedusaLoader#entitiesLoader', `Entity registered - ${resolutionKey}`);
}
/**
@@ -55,5 +55,5 @@ export async function overrideEntity(entityOptions: GetInjectableOption<'entity'
ChildEntity()(originalEntityModule[override.name]);
originalEntityModule[override.name] = entity;
- Utils.log('MedusaLoader#entitiesLoader', `Entity overridden - ${override.name}`);
+ Utils.hydrateLog('MedusaLoader#entitiesLoader', `Entity overridden - ${override.name}`);
}
diff --git a/src/loaders/helpers/apply-middlewares.ts b/src/loaders/helpers/apply-middlewares.ts
new file mode 100644
index 00000000..772c3952
--- /dev/null
+++ b/src/loaders/helpers/apply-middlewares.ts
@@ -0,0 +1,45 @@
+import { NextFunction, Response, Router } from 'express';
+import { GetInjectableOption, GetInjectableOptions, MedusaAuthenticatedRequest, MedusaRequest } from '../../types';
+import { Utils } from '../../utils';
+
+export function applyBeforeAuthMiddleware(app: Router, middlewares: GetInjectableOptions<'middleware'>): void {
+ for (const middlewareOptions of middlewares) {
+ const { requireAuth } = middlewareOptions;
+ if (!requireAuth) {
+ applyMiddleware(app, middlewareOptions);
+ Utils.hydrateLog(
+ 'MedusaLoader#middlewaresLoader',
+ `Middleware registered before auth - ${middlewareOptions.metatype.name}`
+ );
+ }
+ }
+}
+
+export function applyAfterAuthMiddleware(app: Router, middlewares: GetInjectableOptions<'middleware'>): void {
+ for (const middlewareOptions of middlewares) {
+ const { requireAuth } = middlewareOptions;
+ if (requireAuth) {
+ applyMiddleware(app, middlewareOptions);
+ Utils.hydrateLog(
+ 'MedusaLoader#middlewaresLoader',
+ `Middleware registered after auth - ${middlewareOptions.metatype.name}`
+ );
+ }
+ }
+}
+
+function applyMiddleware(app: Router, middleware: GetInjectableOption<'middleware'>): void {
+ app.use(async (req: MedusaRequest | MedusaAuthenticatedRequest, res: Response, next: NextFunction) => {
+ const shouldHandle = middleware.routes.some((route) => {
+ return (
+ (route.method === 'all' || req.method.toLowerCase() === route.method.toLowerCase()) &&
+ (route.path === '*' || req.originalUrl === route.path)
+ );
+ });
+ if (shouldHandle) {
+ await new middleware.metatype().consume(req, res, next);
+ return;
+ }
+ return next();
+ });
+}
diff --git a/src/loaders/helpers/apply-routers.ts b/src/loaders/helpers/apply-routers.ts
new file mode 100644
index 00000000..e37cf5fe
--- /dev/null
+++ b/src/loaders/helpers/apply-routers.ts
@@ -0,0 +1,27 @@
+import { Router } from 'express';
+import { GetInjectableOptions, RoutesInjectionRouterConfiguration } from '../../types';
+
+export function applyBeforeAuthRouters(app: Router, routesOptions: GetInjectableOptions<'router'>): void {
+ for (const routeOptions of routesOptions) {
+ routeOptions.routes.forEach((route) => {
+ if (!route.requiredAuth) {
+ applyRoute(app, route);
+ }
+ });
+ }
+}
+
+export function applyAfterAuthRouters(app: Router, routesOptions: GetInjectableOptions<'router'>): void {
+ for (const routeOptions of routesOptions) {
+ routeOptions.routes.forEach((route) => {
+ if (route.requiredAuth) {
+ applyRoute(app, route);
+ }
+ });
+ }
+}
+
+function applyRoute(app: Router, route: RoutesInjectionRouterConfiguration): void {
+ const { method, path, handlers } = route;
+ app[method.toLowerCase()](path, ...handlers);
+}
diff --git a/src/loaders/index.ts b/src/loaders/index.ts
index de4e5513..881cda57 100644
--- a/src/loaders/index.ts
+++ b/src/loaders/index.ts
@@ -1,6 +1,6 @@
export * from './services.loader';
-export * from './routes.loader';
-export * from './api.loader';
+export * from './admin-api.loader';
+export * from './store-api.loader';
export * from './repository.loader';
export * from './database.loader';
export * from './entities.loader';
diff --git a/src/loaders/middlewares.loader.ts b/src/loaders/middlewares.loader.ts
deleted file mode 100644
index 07c5f0c2..00000000
--- a/src/loaders/middlewares.loader.ts
+++ /dev/null
@@ -1,68 +0,0 @@
-import { Express, NextFunction, Response } from 'express';
-import { AwilixContainer } from 'awilix';
-import MiddlewareService from '@medusajs/medusa/dist/services/middleware';
-import { GetInjectableOption, GetInjectableOptions, MedusaAuthenticatedRequest, MedusaRequest, Utils } from './';
-
-/**
- * @internal
- * Register custom middlewares into medusa middleware service to be applied at the right moment.
- * @param app
- * @param container
- * @param middlewares
- */
-export function middlewaresLoader(
- app: Express,
- container: AwilixContainer,
- middlewares: GetInjectableOptions<'middleware'>
-): void {
- const medusaMiddlewareService = container.resolve('middlewareService') as MiddlewareService;
-
- for (const middlewareOptions of middlewares) {
- const { requireAuth } = middlewareOptions;
- const wrappedMiddleware = wrapMiddleware(middlewareOptions);
- if (!requireAuth) {
- medusaMiddlewareService.addPreAuthentication(wrappedMiddleware, { app });
- Utils.log(
- 'MedusaLoader#middlewaresLoader',
- `Middleware registered before auth - ${middlewareOptions.metatype.name}`
- );
- } else {
- medusaMiddlewareService.addPostAuthentication(wrappedMiddleware, { app });
- Utils.log(
- 'MedusaLoader#middlewaresLoader',
- `Middleware registered after auth - ${middlewareOptions.metatype.name}`
- );
- }
- }
-}
-
-export function wrapMiddleware(
- middleware: GetInjectableOption<'middleware'>
-): ({ app }: { app: Express }) => (...args: unknown[]) => void {
- return ({
- app,
- }: {
- app: Express;
- }): ((
- err: unknown,
- req: MedusaRequest | MedusaAuthenticatedRequest,
- res: Response,
- next: NextFunction
- ) => void | Promise) => {
- app.use(async (req: MedusaRequest | MedusaAuthenticatedRequest, res: Response, next: NextFunction) => {
- const shouldHandle = middleware.routes.some((route) => {
- return (
- (route.method === 'all' || req.method.toLowerCase() === route.method.toLowerCase()) &&
- (route.path === '*' || req.originalUrl === route.path)
- );
- });
- if (shouldHandle) {
- await new middleware.metatype().consume(req, res, next);
- return;
- }
- return next();
- });
- return (err: unknown, req: MedusaRequest | MedusaAuthenticatedRequest, res: Response, next: NextFunction) =>
- next();
- };
-}
diff --git a/src/loaders/migrations.loader.ts b/src/loaders/migrations.loader.ts
index 6c12de9e..6786ec00 100644
--- a/src/loaders/migrations.loader.ts
+++ b/src/loaders/migrations.loader.ts
@@ -17,7 +17,7 @@ export async function migrationsLoader(
await dbConnection.runMigrations().then((ranMigrations: Migration[]) => {
for (const migration of ranMigrations) {
- Utils.log('MedusaLoader#runCustomMigrations', `Migration applied - ${migration.name}`);
+ Utils.hydrateLog('MedusaLoader#runCustomMigrations', `Migration applied - ${migration.name}`);
}
});
}
diff --git a/src/loaders/repository.loader.ts b/src/loaders/repository.loader.ts
index 01010505..357e0e60 100644
--- a/src/loaders/repository.loader.ts
+++ b/src/loaders/repository.loader.ts
@@ -37,7 +37,7 @@ export function registerRepository(container: AwilixContainer, repositoryOptions
[resolutionKey]: asClass(repository),
});
- Utils.log('MedusaLoader#repositoriesLoader', `Repository registered - ${resolutionKey}`);
+ Utils.hydrateLog('MedusaLoader#repositoriesLoader', `Repository registered - ${resolutionKey}`);
}
/**
@@ -62,5 +62,5 @@ export async function overrideRepository(repositoryOptions: GetInjectableOption<
}
originalRepository[override.name] = metatype;
- Utils.log('MedusaLoader#repositoriesLoader', `Repository overridden - ${metatype.name}`);
+ Utils.hydrateLog('MedusaLoader#repositoriesLoader', `Repository overridden - ${metatype.name}`);
}
diff --git a/src/loaders/routes.loader.ts b/src/loaders/routes.loader.ts
deleted file mode 100644
index eae10091..00000000
--- a/src/loaders/routes.loader.ts
+++ /dev/null
@@ -1,34 +0,0 @@
-import { GetInjectableOptions, MedusaAuthenticatedRequest, RoutesInjectionRouterConfiguration } from './';
-import { Express, NextFunction, Request, Response } from 'express';
-
-export function authenticatedRoutesLoader(routesOptions: GetInjectableOptions<'router'>, app: Express): void {
- for (const routeOptions of routesOptions) {
- routeOptions.routes.forEach((route) => {
- if (route.requiredAuth) {
- registerRoute(app, route);
- }
- });
- }
-}
-
-export function unauthenticatedRoutesLoader(routesOptions: GetInjectableOptions<'router'>, app: Express): void {
- for (const routeOptions of routesOptions) {
- routeOptions.routes.forEach((route) => {
- if (!route.requiredAuth) {
- registerRoute(app, route);
- }
- });
- }
-}
-
-function registerRoute(app: Express, route: RoutesInjectionRouterConfiguration): void {
- const { method, path, handlers } = route;
- app[method.toLowerCase()](
- path,
- handlers.map(handler => {
- return async (req: MedusaAuthenticatedRequest | Request, res: Response, next: NextFunction) => {
- await handler(req, res, next);
- };
- })
- );
-}
diff --git a/src/loaders/services.loader.ts b/src/loaders/services.loader.ts
index 751b8881..589d2fa6 100644
--- a/src/loaders/services.loader.ts
+++ b/src/loaders/services.loader.ts
@@ -42,7 +42,7 @@ export function registerService(
[resolutionKey]: asFunction((cradle) => new metatype(cradle, configModule), { lifetime: scope || 'SINGLETON' }),
});
- Utils.log('MedusaLoader#servicesLoader', `Service registered - ${resolutionKey}`);
+ Utils.hydrateLog('MedusaLoader#servicesLoader', `Service registered - ${resolutionKey}`);
}
/**
@@ -66,5 +66,5 @@ export function overrideService(
}),
});
- Utils.log('MedusaLoader#servicesLoader', `Service overridden - ${metatype.name}`);
+ Utils.hydrateLog('MedusaLoader#servicesLoader', `Service overridden - ${metatype.name}`);
}
diff --git a/src/loaders/store-api.loader.ts b/src/loaders/store-api.loader.ts
new file mode 100644
index 00000000..3746edcc
--- /dev/null
+++ b/src/loaders/store-api.loader.ts
@@ -0,0 +1,59 @@
+import { Router } from 'express';
+import { GetInjectableOptions } from './';
+import { applyAfterAuthMiddleware, applyBeforeAuthMiddleware } from './helpers/apply-middlewares';
+import { applyAfterAuthRouters, applyBeforeAuthRouters } from './helpers/apply-routers';
+
+/**
+ * @internal
+ * Apply middlewares and routes on store API.
+ * @param app
+ * @param middlewares
+ * @param routers
+ */
+export async function storeApiLoader(
+ app: Router,
+ middlewares: GetInjectableOptions<'middleware'>,
+ routers: GetInjectableOptions<'router'>
+) {
+ const storeMiddlewares = middlewares
+ .map((middleware) => ({
+ ...middleware,
+ routes: middleware.routes.filter((route) => {
+ if (route.path.startsWith('/store')) {
+ route.path = route.path.replace('/store', '');
+ return true;
+ }
+ return false;
+ }),
+ }))
+ .filter((middleware) => middleware.routes.length);
+
+ const storeRouters = routers
+ .map((router) => ({
+ ...router,
+ routes: router.routes.filter((route) => {
+ if (route.path.startsWith('/store')) {
+ route.path = route.path.replace('/store', '');
+ return true;
+ }
+ return false;
+ }),
+ }))
+ .filter((route) => route.routes.length);
+
+ const storeAuthRouteLoader = await import('@medusajs/medusa/dist/api/routes/store/auth');
+ const originalStoreAuthRouteLoader = storeAuthRouteLoader.default;
+ storeAuthRouteLoader.default = (app: Router): void => {
+ applyBeforeAuthMiddleware(app, storeMiddlewares);
+ applyBeforeAuthRouters(app, storeRouters);
+ originalStoreAuthRouteLoader(app);
+ };
+
+ const storeCollectionRouteLoader = await import('@medusajs/medusa/dist/api/routes/store/collections');
+ const originalStoreCollectionRouteLoader = storeCollectionRouteLoader.default;
+ storeCollectionRouteLoader.default = (app: Router): void => {
+ applyAfterAuthMiddleware(app, storeMiddlewares);
+ applyAfterAuthRouters(app, storeRouters);
+ originalStoreCollectionRouteLoader(app);
+ };
+}
diff --git a/src/loaders/tests/middlewares.loader.spec.ts b/src/loaders/tests/middlewares.loader.spec.ts
deleted file mode 100644
index 602397e6..00000000
--- a/src/loaders/tests/middlewares.loader.spec.ts
+++ /dev/null
@@ -1,60 +0,0 @@
-// TODO fix the fact that medusa is using babel
-import 'core-js/stable';
-import 'regenerator-runtime/runtime';
-
-import { asValue, createContainer } from 'awilix';
-import { Middleware, Module } from '../../decorators';
-import { MedusaAuthenticatedRequest, MedusaMiddleware } from '../../types';
-import { NextFunction, Request, Response } from 'express';
-import { middlewaresLoader, wrapMiddleware } from '../middlewares.loader';
-import { metadataReader } from '../../metadata-reader';
-import { MEDUSA_RESOLVER_KEYS } from '../../constants';
-import express = require('express');
-
-const MiddlewareServiceMock = {
- addPreAuthentication: jest.fn(),
- addPostAuthentication: jest.fn(),
-};
-
-@Middleware({ requireAuth: false, routes: [{ path: '/admin/test', method: 'get' }] })
-class PreAuthUserMiddleware implements MedusaMiddleware {
- /* eslint-disable @typescript-eslint/no-unused-vars */
- consume(req: MedusaAuthenticatedRequest | Request, res: Response, next: NextFunction): void | Promise {
- return;
- }
-}
-
-@Middleware({ requireAuth: true, routes: [{ path: '/admin/test', method: 'get' }] })
-class PostAuthUserMiddleware implements MedusaMiddleware {
- /* eslint-disable @typescript-eslint/no-unused-vars */
- consume(req: MedusaAuthenticatedRequest | Request, res: Response, next: NextFunction): void | Promise {
- return;
- }
-}
-
-@Module({ imports: [PreAuthUserMiddleware, PostAuthUserMiddleware] })
-class UserModule {}
-
-describe('Middlewares loader', () => {
- const app = express();
- const container = createContainer();
- container.register({
- [MEDUSA_RESOLVER_KEYS.MiddlewareService]: asValue(MiddlewareServiceMock),
- });
-
- it('should call the appropriate method base on requiredAuth option', async () => {
- expect(MiddlewareServiceMock.addPostAuthentication).not.toHaveBeenCalled();
- expect(MiddlewareServiceMock.addPreAuthentication).not.toHaveBeenCalled();
-
- const components = metadataReader([UserModule]);
- middlewaresLoader(app, container, components.get('middleware'));
-
- console.log(wrapMiddleware(components.get('middleware')[0]));
-
- expect(MiddlewareServiceMock.addPreAuthentication).toHaveBeenCalled();
- expect(MiddlewareServiceMock.addPreAuthentication).toHaveBeenCalledWith(expect.any(Function), { app });
-
- expect(MiddlewareServiceMock.addPostAuthentication).toHaveBeenCalled();
- expect(MiddlewareServiceMock.addPostAuthentication).toHaveBeenCalledWith(expect.any(Function), { app });
- });
-});
diff --git a/src/types.ts b/src/types.ts
index 9e6d58db..51283fa2 100644
--- a/src/types.ts
+++ b/src/types.ts
@@ -74,7 +74,7 @@ export type MiddlewareInjectionOptions = {
* Defines the injection options for routes.
*/
export type ValidatorInjectionOptions = {
- override?: Type;
+ override: Type;
};
/**
diff --git a/src/utils.ts b/src/utils.ts
index 032c375e..082f6a61 100644
--- a/src/utils.ts
+++ b/src/utils.ts
@@ -1,6 +1,7 @@
/* eslint-disable @typescript-eslint/no-var-requires */
const chalk = require('chalk');
import { Express } from 'express';
+import * as getEndpoints from 'express-list-endpoints';
import { Connection, EntityManager, EntitySubscriberInterface, Repository } from 'typeorm';
import { Constructor, MixinReturnType } from './types';
@@ -9,6 +10,8 @@ import { Constructor, MixinReturnType } from './types';
* Utilities helper methods.
*/
export class Utils {
+ static logs: string[][] = [];
+
/**
* For repository context, you should extends repository and the medusa target repository.
* Since it is not possible to use multiple extend, you can use that utilities to apply multiple extends.
@@ -52,65 +55,44 @@ export class Utils {
}
/**
- * Log all the routes from the express instance.
- * @param express Express instance
- */
- static logRoutes(express: Express): void {
- express._router.stack.forEach(Utils.printRoutes.bind(null, []));
- }
-
- /**
+ * @internal
* Prepare the log to be shown to be consistent everywhere.
* @param context Where the log comes from
* @param description The description of the action logged
* @param variables The variable that populate the logs
*/
- static log(context: string, description: string, ...variables: string[]): void {
+ static hydrateLog(context: string, description: string, ...variables: string[]): void {
const date = new Date().toLocaleString('en-US', { hour12: true });
- console.log(
+ this.logs.push([
`${chalk.blue(`[Server] -`)} ${date} ${chalk.yellow(`[${context}]`)} ${chalk.blue(description)}`,
- ...variables
- );
+ ...variables,
+ ]);
}
/**
- * @private
- * Print all the routes from `path` and `layer` that comes from express.
- * @param path
- * @param layer
+ * @internal
+ * Prepare the logs the show all available routes on the app.
+ * @param app
*/
- private static printRoutes(path: string[], layer: any) {
- if (layer.route) {
- layer.route.stack.forEach(Utils.printRoutes.bind(null, path.concat(Utils.splitRoutes(layer.route.path))));
- } else if (layer.name === 'router' && layer.handle.stack) {
- layer.handle.stack.forEach(Utils.printRoutes.bind(null, path.concat(Utils.splitRoutes(layer.regexp))));
- } else if (layer.method) {
- Utils.log(
- 'MedusaLoader',
- 'Route Mapped {/%s, %s}',
- path.concat(Utils.splitRoutes(layer.regexp)).filter(Boolean).join('/'),
- layer.method.toUpperCase()
- );
+ static hydrateRouteLog(app: Express): void {
+ const endPoints = getEndpoints(app);
+ for (const endPoint of endPoints) {
+ endPoint.methods.map((method) => {
+ this.hydrateLog('MedusaLoader', 'Route Mapped {/%s, %s}', endPoint.path, method);
+ });
}
}
/**
- * @private
- * Split the routes contained in express.
- * @param thing
+ * @internal
+ * Display the logs that has been registered during the build time.
*/
- private static splitRoutes(thing: string | (RegExp & { fast_slash: boolean })) {
- if (typeof thing === 'string') {
- return thing.split('/');
- } else if (thing.fast_slash) {
- return '';
- } else {
- const match = thing
- .toString()
- .replace('\\/?', '')
- .replace('(?=\\/|$)', '$')
- .match(/^\/\^((?:\\[.*+?^${}()|[\]\\\/]|[^.*+?^${}()|[\]\\\/])*)\$\//);
- return match ? match[1].replace(/\\(.)/g, '$1').split('/') : '';
+ static displayLogs() {
+ if (this.logs.length) {
+ this.logs.map((logArgs) => {
+ console.log(...logArgs);
+ });
+ this.logs.length = 0;
}
}
}