fix(medusa-plugin-economic,medusa-plugin-mailchimp,medusa-plugin-restock-notification,medusa-plugin-sendgrid,medusa-plugin-wishlist): Temporarily remove payload validation in some plugins (#3763)
* Temporarily remove payload validation in some plugins * Add changeset * chore: Remove commented out code * Revert discount generator plugin --------- Co-authored-by: olivermrbl <oliver@mrbltech.com> Co-authored-by: Oliver Windall Juhl <59018053+olivermrbl@users.noreply.github.com>
This commit is contained in:
7 files changed
+79
-172
No files matched your search
@@ -0,0 +1,10 @@
|
|||||||
|
---
|
||||||
|
"medusa-plugin-discount-generator": patch
|
||||||
|
"medusa-plugin-economic": patch
|
||||||
|
"medusa-plugin-mailchimp": patch
|
||||||
|
"medusa-plugin-restock-notification": patch
|
||||||
|
"medusa-plugin-sendgrid": patch
|
||||||
|
"medusa-plugin-wishlist": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
fix(plugin-discount-generator,plugin-economic,plugin-mailchimp,plugin-restock-notification,plugin-sendgrid,plugin-wishlist): Temporarily remove payload validation in some plugins
|
||||||
@@ -1,18 +1,5 @@
|
|||||||
export default async (req, res) => {
|
export default async (req, res) => {
|
||||||
const schema = Validator.object().keys({
|
const economicService = req.scope.resolve("economicService")
|
||||||
orderId: Validator.string().required(),
|
await economicService.bookEconomicInvoice(req.body.orderId)
|
||||||
})
|
res.sendStatus(200)
|
||||||
|
|
||||||
const { value, error } = schema.validate(req.body)
|
|
||||||
if (error) {
|
|
||||||
throw new MedusaError(MedusaError.Types.INVALID_DATA, error.details)
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
const economicService = req.scope.resolve("economicService")
|
|
||||||
await economicService.bookEconomicInvoice(value.orderId)
|
|
||||||
res.sendStatus(200)
|
|
||||||
} catch (error) {
|
|
||||||
throw error
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -1,18 +1,5 @@
|
|||||||
export default async (req, res) => {
|
export default async (req, res) => {
|
||||||
const schema = Validator.object().keys({
|
const economicService = req.scope.resolve("economicService")
|
||||||
orderId: Validator.string().required(),
|
await economicService.draftEconomicInvoice(req.body.orderId)
|
||||||
})
|
res.sendStatus(200)
|
||||||
|
|
||||||
const { value, error } = schema.validate(req.body)
|
|
||||||
if (error) {
|
|
||||||
throw new MedusaError(MedusaError.Types.INVALID_DATA, error.details)
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
const economicService = req.scope.resolve("economicService")
|
|
||||||
await economicService.draftEconomicInvoice(value.orderId)
|
|
||||||
res.sendStatus(200)
|
|
||||||
} catch (error) {
|
|
||||||
throw error
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -1,22 +1,8 @@
|
|||||||
import { Validator, MedusaError } from "medusa-core-utils"
|
|
||||||
|
|
||||||
export default async (req, res) => {
|
export default async (req, res) => {
|
||||||
const schema = Validator.object().keys({
|
const mailchimpService = req.scope.resolve("mailchimpService")
|
||||||
email: Validator.string().required(),
|
await mailchimpService.subscribeNewsletter(
|
||||||
data: Validator.object().default({}),
|
req.body.email,
|
||||||
})
|
req.body.data || {}
|
||||||
|
)
|
||||||
const { value, error } = schema.validate(req.body)
|
res.sendStatus(200)
|
||||||
if (error) {
|
|
||||||
throw new MedusaError(MedusaError.Types.INVALID_DATA, error.details)
|
|
||||||
}
|
|
||||||
console.log(value)
|
|
||||||
|
|
||||||
try {
|
|
||||||
const mailchimpService = req.scope.resolve("mailchimpService")
|
|
||||||
await mailchimpService.subscribeNewsletter(value.email, value.data)
|
|
||||||
res.sendStatus(200)
|
|
||||||
} catch (err) {
|
|
||||||
throw err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -1,23 +1,10 @@
|
|||||||
import { Validator, MedusaError } from "medusa-core-utils"
|
|
||||||
|
|
||||||
export default async (req, res) => {
|
export default async (req, res) => {
|
||||||
const { variant_id } = req.params
|
const { variant_id } = req.params
|
||||||
|
|
||||||
const schema = Validator.object().keys({
|
|
||||||
email: Validator.string().required(),
|
|
||||||
})
|
|
||||||
|
|
||||||
const { value, error } = schema.validate(req.body)
|
|
||||||
if (error) {
|
|
||||||
res.status(400).json({ message: error.message })
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const restockNotificationService = req.scope.resolve(
|
const restockNotificationService = req.scope.resolve(
|
||||||
"restockNotificationService"
|
"restockNotificationService"
|
||||||
)
|
)
|
||||||
await restockNotificationService.addEmail(variant_id, value.email)
|
await restockNotificationService.addEmail(variant_id, req.body.email)
|
||||||
res.sendStatus(201)
|
res.sendStatus(201)
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
res.status(400).json({ message: err.message })
|
res.status(400).json({ message: err.message })
|
||||||
|
|||||||
@@ -1,28 +1,10 @@
|
|||||||
import { Validator, MedusaError } from "medusa-core-utils"
|
|
||||||
|
|
||||||
export default async (req, res) => {
|
export default async (req, res) => {
|
||||||
const schema = Validator.object().keys({
|
const sendgridService = req.scope.resolve("sendgridService")
|
||||||
template_id: Validator.string().required(),
|
await sendgridService.sendEmail(
|
||||||
from: Validator.string().required(),
|
req.body.template_id,
|
||||||
to: Validator.string().required(),
|
req.body.from,
|
||||||
data: Validator.object().optional().default({}),
|
req.body.to,
|
||||||
})
|
req.body.data || {}
|
||||||
|
)
|
||||||
const { value, error } = schema.validate(req.body)
|
res.sendStatus(200)
|
||||||
if (error) {
|
|
||||||
throw new MedusaError(MedusaError.Types.INVALID_DATA, error.details)
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
const sendgridService = req.scope.resolve("sendgridService")
|
|
||||||
await sendgridService.sendEmail(
|
|
||||||
value.template_id,
|
|
||||||
value.from,
|
|
||||||
value.to,
|
|
||||||
value.data
|
|
||||||
)
|
|
||||||
res.sendStatus(200)
|
|
||||||
} catch (err) {
|
|
||||||
throw err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
import { Router } from "express"
|
|
||||||
import bodyParser from "body-parser"
|
import bodyParser from "body-parser"
|
||||||
import { Validator, MedusaError } from "medusa-core-utils"
|
import { Router } from "express"
|
||||||
import jwt from "jsonwebtoken"
|
import jwt from "jsonwebtoken"
|
||||||
|
import { MedusaError } from "medusa-core-utils"
|
||||||
|
|
||||||
const JWT_SECRET = process.env.JWT_SECRET || ""
|
const JWT_SECRET = process.env.JWT_SECRET || ""
|
||||||
|
|
||||||
@@ -9,99 +9,67 @@ export default () => {
|
|||||||
const app = Router()
|
const app = Router()
|
||||||
|
|
||||||
app.delete("/:id/wishlist", bodyParser.json(), async (req, res) => {
|
app.delete("/:id/wishlist", bodyParser.json(), async (req, res) => {
|
||||||
const schema = Validator.object().keys({
|
const customerService = req.scope.resolve("customerService")
|
||||||
index: Validator.number().required(),
|
|
||||||
|
let customer = await customerService.retrieve(req.params.id)
|
||||||
|
const wishlist = (customer.metadata && customer.metadata.wishlist) || []
|
||||||
|
|
||||||
|
const newWishlist = [...wishlist]
|
||||||
|
newWishlist.splice(req.body.index, 1)
|
||||||
|
|
||||||
|
customer = await customerService.update(customer.id, {
|
||||||
|
metadata: { wishlist: newWishlist },
|
||||||
})
|
})
|
||||||
|
|
||||||
const { value, error } = schema.validate(req.body)
|
res.json({ customer })
|
||||||
if (error) {
|
|
||||||
throw new MedusaError(MedusaError.Types.INVALID_DATA, error.details)
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
const customerService = req.scope.resolve("customerService")
|
|
||||||
|
|
||||||
let customer = await customerService.retrieve(req.params.id)
|
|
||||||
const wishlist = (customer.metadata && customer.metadata.wishlist) || []
|
|
||||||
|
|
||||||
const newWishlist = [...wishlist]
|
|
||||||
newWishlist.splice(value.index, 1)
|
|
||||||
|
|
||||||
customer = await customerService.update(customer.id, {
|
|
||||||
metadata: { wishlist: newWishlist },
|
|
||||||
})
|
|
||||||
|
|
||||||
res.json({ customer })
|
|
||||||
} catch (err) {
|
|
||||||
throw err
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
app.post("/:id/wishlist", bodyParser.json(), async (req, res) => {
|
app.post("/:id/wishlist", bodyParser.json(), async (req, res) => {
|
||||||
const schema = Validator.object().keys({
|
const lineItemService = req.scope.resolve("lineItemService")
|
||||||
variant_id: Validator.string().required(),
|
const customerService = req.scope.resolve("customerService")
|
||||||
quantity: Validator.number().required(),
|
const regionService = req.scope.resolve("regionService")
|
||||||
metadata: Validator.object().optional(),
|
|
||||||
})
|
|
||||||
|
|
||||||
const { value, error } = schema.validate(req.body)
|
let customer = await customerService.retrieve(req.params.id)
|
||||||
if (error) {
|
|
||||||
throw new MedusaError(MedusaError.Types.INVALID_DATA, error.details)
|
const regions = await regionService.list()
|
||||||
|
if (regions.length) {
|
||||||
|
const lineItem = await lineItemService.generate(
|
||||||
|
req.body.variant_id,
|
||||||
|
regions[0].id,
|
||||||
|
req.body.quantity,
|
||||||
|
{ metadata: req.body.metadata }
|
||||||
|
)
|
||||||
|
|
||||||
|
const wishlist = (customer.metadata && customer.metadata.wishlist) || []
|
||||||
|
customer = await customerService.update(customer.id, {
|
||||||
|
metadata: { wishlist: [...wishlist, lineItem] },
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
res.json({ customer })
|
||||||
const lineItemService = req.scope.resolve("lineItemService")
|
|
||||||
const customerService = req.scope.resolve("customerService")
|
|
||||||
const regionService = req.scope.resolve("regionService")
|
|
||||||
|
|
||||||
let customer = await customerService.retrieve(req.params.id)
|
|
||||||
|
|
||||||
const regions = await regionService.list()
|
|
||||||
if (regions.length) {
|
|
||||||
const lineItem = await lineItemService.generate(
|
|
||||||
value.variant_id,
|
|
||||||
regions[0].id,
|
|
||||||
value.quantity,
|
|
||||||
{ metadata: value.metadata }
|
|
||||||
)
|
|
||||||
|
|
||||||
const wishlist = (customer.metadata && customer.metadata.wishlist) || []
|
|
||||||
customer = await customerService.update(customer.id, {
|
|
||||||
metadata: { wishlist: [...wishlist, lineItem] },
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
res.json({ customer })
|
|
||||||
} catch (err) {
|
|
||||||
throw err
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
app.post("/:id/wishlist/share-token", bodyParser.json(), async (req, res) => {
|
app.post("/:id/wishlist/share-token", bodyParser.json(), async (req, res) => {
|
||||||
try {
|
const customerService = req.scope.resolve("customerService")
|
||||||
const customerService = req.scope.resolve("customerService")
|
|
||||||
|
|
||||||
let customer = await customerService.retrieve(req.params.id)
|
const customer = await customerService.retrieve(req.params.id)
|
||||||
|
|
||||||
// check customer has wishlist else throw 400 bad request
|
// check customer has wishlist else throw 400 bad request
|
||||||
if (!customer?.metadata?.wishlist) {
|
if (!customer?.metadata?.wishlist) {
|
||||||
throw new MedusaError(
|
throw new MedusaError(
|
||||||
Medusa.Types.INVALID_DATA,
|
MedusaError.Types.INVALID_DATA,
|
||||||
"Invalid data - Customer doesn't have a wishlist"
|
"Invalid data - Customer doesn't have a wishlist"
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
const token = jwt.sign(
|
|
||||||
{
|
|
||||||
customer_id: customer.id,
|
|
||||||
},
|
|
||||||
JWT_SECRET
|
|
||||||
)
|
)
|
||||||
|
|
||||||
res.json({ share_token: token })
|
|
||||||
} catch (err) {
|
|
||||||
throw err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const token = jwt.sign(
|
||||||
|
{
|
||||||
|
customer_id: customer.id,
|
||||||
|
},
|
||||||
|
JWT_SECRET
|
||||||
|
)
|
||||||
|
|
||||||
|
res.json({ share_token: token })
|
||||||
})
|
})
|
||||||
|
|
||||||
return app
|
return app
|
||||||
|
|||||||
Reference in new issue
Block a user