Merge branch 'master' of github.com:medusajs/medusa
This commit is contained in:
commit
07e8ae04a7
11 files changed
+154
-23
No files matched your search
@@ -3,12 +3,19 @@ import middlewares from "../../../middlewares"
|
||||
|
||||
const route = Router()
|
||||
|
||||
export default app => {
|
||||
export default (app, container) => {
|
||||
const middlewareService = container.resolve("middlewareService")
|
||||
|
||||
app.use("/carts", route)
|
||||
|
||||
route.get("/:id", middlewares.wrap(require("./get-cart").default))
|
||||
|
||||
route.post("/", middlewares.wrap(require("./create-cart").default))
|
||||
route.post(
|
||||
"/",
|
||||
middlewareService.usePreCartCreation(),
|
||||
middlewares.wrap(require("./create-cart").default)
|
||||
)
|
||||
|
||||
route.post("/:id", middlewares.wrap(require("./update-cart").default))
|
||||
|
||||
// Line items
|
||||
|
||||
@@ -30,7 +30,7 @@ export default (app, container, config) => {
|
||||
customerRoutes(route, container)
|
||||
productRoutes(route)
|
||||
orderRoutes(route)
|
||||
cartRoutes(route)
|
||||
cartRoutes(route, container)
|
||||
shippingOptionRoutes(route)
|
||||
regionRoutes(route)
|
||||
|
||||
|
||||
@@ -109,6 +109,10 @@ function registerMedusaMiddleware(pluginDetails, container) {
|
||||
pluginDetails.options
|
||||
)
|
||||
}
|
||||
|
||||
if (module.preCartCreation) {
|
||||
middlewareService.addPreCartCreation(module.preCartCreation)
|
||||
}
|
||||
}
|
||||
|
||||
function registerCoreRouters(pluginDetails, container) {
|
||||
|
||||
@@ -7,6 +7,7 @@ class MiddlewareService {
|
||||
constructor(container) {
|
||||
this.postAuthentication_ = []
|
||||
this.preAuthentication_ = []
|
||||
this.preCartCreation_ = []
|
||||
this.routers = {}
|
||||
}
|
||||
|
||||
@@ -65,6 +66,17 @@ class MiddlewareService {
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a middleware function to be called before cart creation
|
||||
* @param {function} middleware - the middleware function. Should return a
|
||||
* middleware function.
|
||||
* @return {void}
|
||||
*/
|
||||
addPreCartCreation(middleware) {
|
||||
this.validateMiddleware_(middleware)
|
||||
this.preCartCreation_.push(middleware)
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds post authentication middleware to an express app.
|
||||
* @param {ExpressApp} app - the express app to add the middleware to
|
||||
@@ -86,6 +98,10 @@ class MiddlewareService {
|
||||
app.use(object.middleware(object.options))
|
||||
}
|
||||
}
|
||||
|
||||
usePreCartCreation() {
|
||||
return this.preCartCreation_
|
||||
}
|
||||
}
|
||||
|
||||
export default MiddlewareService
|
||||
@@ -1965,13 +1965,6 @@ cli-width@^2.0.0:
|
||||
resolved "https://registry.yarnpkg.com/cli-width/-/cli-width-2.2.0.tgz#ff19ede8a9a5e579324147b0c11f0fbcbabed639"
|
||||
integrity sha1-/xnt6Kml5XkyQUewwR8PvLq+1jk=
|
||||
|
||||
client-sessions@^0.8.0:
|
||||
version "0.8.0"
|
||||
resolved "https://registry.yarnpkg.com/client-sessions/-/client-sessions-0.8.0.tgz#a7d8c5558ad5d56f2a199f3533eb654b5df893fd"
|
||||
integrity sha1-p9jFVYrV1W8qGZ81M+tlS134k/0=
|
||||
dependencies:
|
||||
cookies "^0.7.0"
|
||||
|
||||
cliui@^6.0.0:
|
||||
version "6.0.0"
|
||||
resolved "https://registry.yarnpkg.com/cliui/-/cliui-6.0.0.tgz#511d702c0c4e41ca156d7d0e96021f23e13225b1"
|
||||
@@ -2178,14 +2171,6 @@ cookiejar@^2.1.0:
|
||||
resolved "https://registry.yarnpkg.com/cookiejar/-/cookiejar-2.1.2.tgz#dd8a235530752f988f9a0844f3fc589e3111125c"
|
||||
integrity sha512-Mw+adcfzPxcPeI+0WlvRrr/3lGVO0bD75SxX6811cxSh1Wbxx7xZBGK1eVtDf6si8rg2lhnUjsVLMFMfbRIuwA==
|
||||
|
||||
cookies@^0.7.0:
|
||||
version "0.7.3"
|
||||
resolved "https://registry.yarnpkg.com/cookies/-/cookies-0.7.3.tgz#7912ce21fbf2e8c2da70cf1c3f351aecf59dadfa"
|
||||
integrity sha512-+gixgxYSgQLTaTIilDHAdlNPZDENDQernEMiIcZpYYP14zgHsCt4Ce1FEjFtcp6GefhozebB6orvhAAWx/IS0A==
|
||||
dependencies:
|
||||
depd "~1.1.2"
|
||||
keygrip "~1.0.3"
|
||||
|
||||
copy-descriptor@^0.1.0:
|
||||
version "0.1.1"
|
||||
resolved "https://registry.yarnpkg.com/copy-descriptor/-/copy-descriptor-0.1.1.tgz#676f6eb3c39997c2ee1ac3a924fd6124748f578d"
|
||||
@@ -4363,11 +4348,6 @@ kareem@2.3.1:
|
||||
resolved "https://registry.yarnpkg.com/kareem/-/kareem-2.3.1.tgz#def12d9c941017fabfb00f873af95e9c99e1be87"
|
||||
integrity sha512-l3hLhffs9zqoDe8zjmb/mAN4B8VT3L56EUvKNqLFVs9YlFA+zx7ke1DO8STAdDyYNkeSo1nKmjuvQeI12So8Xw==
|
||||
|
||||
keygrip@~1.0.3:
|
||||
version "1.0.3"
|
||||
resolved "https://registry.yarnpkg.com/keygrip/-/keygrip-1.0.3.tgz#399d709f0aed2bab0a059e0cdd3a5023a053e1dc"
|
||||
integrity sha512-/PpesirAIfaklxUzp4Yb7xBper9MwP6hNRA6BGGUFCgbJ+BM5CKBtsoxinNXkLHAr+GXS1/lSlF2rP7cv5Fl+g==
|
||||
|
||||
kind-of@^3.0.2, kind-of@^3.0.3, kind-of@^3.2.0:
|
||||
version "3.2.2"
|
||||
resolved "https://registry.yarnpkg.com/kind-of/-/kind-of-3.2.2.tgz#31ea21a734bab9bbb0f32466d893aea51e4a3c64"
|
||||
|
||||
Reference in new issue
Block a user