Adds Middleware API (#40)

* Adds test project

* Adds e2e for end-2-end tests

* Update gitignore

* Update loaders

* Creates test project

* v0.1.27

* Upgrade

* dependency fixes

* Load project plugins in the plugin loader

* Issue with instanceof

* Fixes versioning issues

* Adds medusa middleware api

* Adds documentation

* Fixes tests
This commit is contained in:
Sebastian Rindom
2020-05-01 13:33:03 +02:00
committed by GitHub
parent 964e26e310
commit 516bc7675d
46 changed files with 10163 additions and 977 deletions
+21
View File
@@ -0,0 +1,21 @@
let ignore = [`**/dist`]
// Jest needs to compile this code, but generally we don't want this copied
// to output folders
if (process.env.NODE_ENV !== `test`) {
ignore.push(`**/__tests__`)
}
module.exports = {
plugins: [
"@babel/plugin-proposal-class-properties",
"@babel/plugin-transform-instanceof",
],
presets: ["@babel/preset-env"],
env: {
test: {
plugins: ["@babel/plugin-transform-runtime"],
},
},
ignore,
}
+9
View File
@@ -0,0 +1,9 @@
{
"plugins": ["prettier"],
"extends": ["prettier"],
"rules": {
"prettier/prettier": "error",
"semi": "error",
"no-unused-expressions": "true"
}
}
+3
View File
@@ -0,0 +1,3 @@
/node_modules
.env
+8
View File
@@ -0,0 +1,8 @@
{
"endOfLine": "lf",
"semi": false,
"singleQuote": false,
"tabWidth": 2,
"trailingComma": "es5"
}
+3
View File
@@ -0,0 +1,3 @@
module.exports = {
plugins: [`medusa-payment-stripe`, `medusa-plugin-permissions`],
}
+36
View File
@@ -0,0 +1,36 @@
{
"name": "prod-project",
"version": "1.0.0",
"description": "Test project for testing production setup",
"main": "index.js",
"repository": {
"url": "https://github.com/medusajs/medusa",
"directory": "e2e/prod-project"
},
"author": "Sebastian Rindom",
"license": "GPL-3.0",
"devDependencies": {
"@babel/cli": "^7.7.5",
"@babel/core": "^7.7.5",
"@babel/node": "^7.7.4",
"@babel/plugin-proposal-class-properties": "^7.7.4",
"@babel/plugin-transform-instanceof": "^7.8.3",
"@babel/plugin-transform-runtime": "^7.7.6",
"@babel/preset-env": "^7.7.5",
"@babel/register": "^7.7.4",
"@babel/runtime": "^7.7.6",
"cross-env": "^5.2.1",
"eslint": "^6.7.2",
"jest": "^24.9.0",
"nodemon": "^2.0.1",
"prettier": "^2.0.2",
"supertest": "^4.0.2"
},
"dependencies": {
"express": "^4.17.1",
"medusa-payment-stripe": "^0.1.27"
},
"scripts": {
"start": "nodemon --watch plugins/ --watch src/ --exec babel-node node_modules/@medusajs/medusa/dist/app.js"
}
}
+17
View File
@@ -0,0 +1,17 @@
import { Router } from "express"
export default () => {
const app = Router()
app.get("/project-root", async (req, res, next) => {
try {
const testService = req.scope.resolve("testService")
const newHi = await testService.sayHi()
res.status(200).json(newHi)
} catch (e) {
next(e)
}
})
return app
}
+12
View File
@@ -0,0 +1,12 @@
import mongoose from "mongoose"
import { BaseModel } from "medusa-interfaces"
class TestModel extends BaseModel {
static modelName = "test"
static schema = {
title: { type: String, required: true },
}
}
export default TestModel
+16
View File
@@ -0,0 +1,16 @@
import { BaseService } from "medusa-interfaces"
class TestService extends BaseService {
constructor({ testModel }) {
super()
this.testModel_ = testModel
}
async sayHi() {
const res = await this.testModel_.create({ title: "hi" })
return res
}
}
export default TestService
File diff suppressed because it is too large Load Diff