Merge branch 'integration/dummy-project' of github.com:medusajs/medusa into integration/dummy-project
This commit is contained in:
commit
92759c8e47
17 files changed
+17361
-6
No files matched your search
@@ -15,20 +15,20 @@ class DigitalOceanService extends FileService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
upload(file) {
|
upload(file) {
|
||||||
aws.config.setPromisesDependency();
|
aws.config.setPromisesDependency()
|
||||||
aws.config.update({
|
aws.config.update({
|
||||||
accessKeyId: this.accessKeyId_,
|
accessKeyId: this.accessKeyId_,
|
||||||
secretAccessKey: this.secretAccessKey_,
|
secretAccessKey: this.secretAccessKey_,
|
||||||
region: this.region_,
|
region: this.region_,
|
||||||
endpoint: this.endpoint_,
|
endpoint: this.endpoint_,
|
||||||
});
|
})
|
||||||
|
|
||||||
const s3 = new aws.S3();
|
const s3 = new aws.S3()
|
||||||
var params = {
|
var params = {
|
||||||
ACL: 'public-read',
|
ACL: "public-read",
|
||||||
Bucket: this.bucket_,
|
Bucket: this.bucket_,
|
||||||
Body: fs.createReadStream(file.path),
|
Body: fs.createReadStream(file.path),
|
||||||
Key: `${file.originalname}`
|
Key: `${file.originalname}`,
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
@@ -44,7 +44,29 @@ class DigitalOceanService extends FileService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
delete(file) {
|
delete(file) {
|
||||||
console.log(file)
|
aws.config.setPromisesDependency()
|
||||||
|
aws.config.update({
|
||||||
|
accessKeyId: this.accessKeyId_,
|
||||||
|
secretAccessKey: this.secretAccessKey_,
|
||||||
|
region: this.region_,
|
||||||
|
endpoint: this.endpoint_,
|
||||||
|
})
|
||||||
|
|
||||||
|
const s3 = new aws.S3()
|
||||||
|
var params = {
|
||||||
|
Bucket: this.bucket_,
|
||||||
|
Key: `${file}`,
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
s3.deleteObject(params, (err, data) => {
|
||||||
|
if (err) {
|
||||||
|
reject(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
resolve(data)
|
||||||
|
})
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,13 @@
|
|||||||
|
{
|
||||||
|
"plugins": [
|
||||||
|
"@babel/plugin-proposal-class-properties",
|
||||||
|
"@babel/plugin-transform-instanceof",
|
||||||
|
"@babel/plugin-transform-classes"
|
||||||
|
],
|
||||||
|
"presets": ["@babel/preset-env"],
|
||||||
|
"env": {
|
||||||
|
"test": {
|
||||||
|
"plugins": ["@babel/plugin-transform-runtime"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
"plugins": ["prettier"],
|
||||||
|
"extends": ["prettier"],
|
||||||
|
"rules": {
|
||||||
|
"prettier/prettier": "error",
|
||||||
|
"semi": "error",
|
||||||
|
"no-unused-expressions": "true"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
/lib
|
||||||
|
node_modules
|
||||||
|
.DS_store
|
||||||
|
.env*
|
||||||
|
/*.js
|
||||||
|
!index.js
|
||||||
|
!jest.config.js
|
||||||
|
|
||||||
|
/dist
|
||||||
|
|
||||||
|
/api
|
||||||
|
/services
|
||||||
|
/models
|
||||||
|
/subscribers
|
||||||
|
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
/lib
|
||||||
|
node_modules
|
||||||
|
.DS_store
|
||||||
|
.env*
|
||||||
|
/*.js
|
||||||
|
!index.js
|
||||||
|
yarn.lock
|
||||||
|
|
||||||
|
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"endOfLine": "lf",
|
||||||
|
"semi": false,
|
||||||
|
"singleQuote": false,
|
||||||
|
"tabWidth": 2,
|
||||||
|
"trailingComma": "es5"
|
||||||
|
}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
// noop
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
module.exports = {
|
||||||
|
testEnvironment: "node",
|
||||||
|
}
|
||||||
+11482
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,44 @@
|
|||||||
|
{
|
||||||
|
"name": "medusa-plugin-slack-notification",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"description": "Slack notifications",
|
||||||
|
"main": "index.js",
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/medusajs/medusa",
|
||||||
|
"directory": "packages/medusa-plugin-slack-notification"
|
||||||
|
},
|
||||||
|
"author": "Oliver Juhl",
|
||||||
|
"license": "AGPL-3.0-or-later",
|
||||||
|
"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.9.6",
|
||||||
|
"client-sessions": "^0.8.0",
|
||||||
|
"cross-env": "^5.2.1",
|
||||||
|
"eslint": "^6.8.0",
|
||||||
|
"jest": "^25.5.2"
|
||||||
|
},
|
||||||
|
"scripts": {
|
||||||
|
"build": "babel src -d .",
|
||||||
|
"prepare": "cross-env NODE_ENV=production npm run build",
|
||||||
|
"watch": "babel -w src --out-dir . --ignore **/__tests__",
|
||||||
|
"test": "jest"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"@babel/plugin-transform-classes": "^7.9.5",
|
||||||
|
"axios": "^0.19.2",
|
||||||
|
"body-parser": "^1.19.0",
|
||||||
|
"express": "^4.17.1",
|
||||||
|
"medusa-core-utils": "^0.3.0",
|
||||||
|
"medusa-interfaces": "^0.3.0",
|
||||||
|
"medusa-test-utils": "^0.3.0",
|
||||||
|
"moment": "^2.27.0"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,97 @@
|
|||||||
|
import axios from "axios"
|
||||||
|
import moment from "moment"
|
||||||
|
import { BaseService } from "medusa-interfaces"
|
||||||
|
|
||||||
|
class SlackService extends BaseService {
|
||||||
|
/**
|
||||||
|
* @param {Object} options - options defined in `medusa-config.js`
|
||||||
|
* {
|
||||||
|
* slack_url: "https://hooks.slack.com/services/..."
|
||||||
|
* }
|
||||||
|
*/
|
||||||
|
constructor({ orderService, totalsService, regionService }, options) {
|
||||||
|
super()
|
||||||
|
|
||||||
|
this.orderService_ = orderService
|
||||||
|
|
||||||
|
this.totalsService_ = totalsService
|
||||||
|
|
||||||
|
this.regionService_ = regionService
|
||||||
|
|
||||||
|
this.options_ = options
|
||||||
|
}
|
||||||
|
|
||||||
|
async orderNotification(orderId) {
|
||||||
|
const order = await this.orderService_.retrieve(orderId)
|
||||||
|
|
||||||
|
const subtotal = await this.totalsService_.getSubtotal(order)
|
||||||
|
const shippingTotal = await this.totalsService_.getShippingTotal(order)
|
||||||
|
const taxTotal = await this.totalsService_.getTaxTotal(order)
|
||||||
|
const discountTotal = await this.totalsService_.getDiscountTotal(order)
|
||||||
|
const total = await this.totalsService_.getTotal(order)
|
||||||
|
|
||||||
|
let blocks = [
|
||||||
|
{
|
||||||
|
type: "section",
|
||||||
|
text: {
|
||||||
|
type: "mrkdwn",
|
||||||
|
text: `Order *<http://localhost:8000/a/orders/${order._id}|#${order._id}>* has been processed.`,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: "section",
|
||||||
|
text: {
|
||||||
|
type: "mrkdwn",
|
||||||
|
text: `*Customer*\n${order.shipping_address.first_name} ${
|
||||||
|
order.shipping_address.last_name
|
||||||
|
}\n${order.email}\n*Destination*\n${
|
||||||
|
order.shipping_address.address_1
|
||||||
|
}\n${
|
||||||
|
order.shipping_address.city
|
||||||
|
}, ${order.shipping_address.country_code.toUpperCase()}`,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: "section",
|
||||||
|
text: {
|
||||||
|
type: "mrkdwn",
|
||||||
|
text: `*Subtotal*\t${subtotal}\n*Shipping*\t${shippingTotal}\n*Discount Total*\t${discountTotal}\n*Tax*\t${taxTotal}\n*Total*\t${total}`,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
]
|
||||||
|
|
||||||
|
blocks.push({
|
||||||
|
type: "divider",
|
||||||
|
})
|
||||||
|
|
||||||
|
order.items.forEach((lineItem) => {
|
||||||
|
let line = {
|
||||||
|
type: "section",
|
||||||
|
text: {
|
||||||
|
type: "mrkdwn",
|
||||||
|
text: `*${lineItem.title}*\n${lineItem.quantity} x ${
|
||||||
|
!Array.isArray(lineItem.content) && lineItem.content.unit_price
|
||||||
|
}`,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
if (lineItem.thumbnail) {
|
||||||
|
line.accessory.type = "image"
|
||||||
|
line.accessory.image_url = lineItem.thumbnail
|
||||||
|
line.accessory.alt_text = "Item"
|
||||||
|
}
|
||||||
|
|
||||||
|
blocks.push(line)
|
||||||
|
|
||||||
|
blocks.push({
|
||||||
|
type: "divider",
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
return axios.post(this.options_.slack_url, {
|
||||||
|
text: `Order ${order._id} was processed`,
|
||||||
|
blocks,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default SlackService
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
class OrderSubscriber {
|
||||||
|
constructor({ slackService, eventBusService }) {
|
||||||
|
this.slackService_ = slackService
|
||||||
|
|
||||||
|
this.eventBus_ = eventBusService
|
||||||
|
|
||||||
|
this.eventBus_.subscribe("order.placed", async (order) => {
|
||||||
|
await this.slackService_.orderNotification(order._id)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default OrderSubscriber
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
export default [
|
||||||
|
"BE",
|
||||||
|
"BG",
|
||||||
|
"CZ",
|
||||||
|
"DK",
|
||||||
|
"DE",
|
||||||
|
"EE",
|
||||||
|
"IE",
|
||||||
|
"EL",
|
||||||
|
"ES",
|
||||||
|
"FR",
|
||||||
|
"HR",
|
||||||
|
"IT",
|
||||||
|
"CY",
|
||||||
|
"LV",
|
||||||
|
"LT",
|
||||||
|
"LU",
|
||||||
|
"HU",
|
||||||
|
"MT",
|
||||||
|
"NL",
|
||||||
|
"AT",
|
||||||
|
"PL",
|
||||||
|
"PT",
|
||||||
|
"RO",
|
||||||
|
"SI",
|
||||||
|
"SK",
|
||||||
|
"FI",
|
||||||
|
"SE",
|
||||||
|
"UK",
|
||||||
|
]
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
"use strict";
|
||||||
|
|
||||||
|
Object.defineProperty(exports, "__esModule", {
|
||||||
|
value: true
|
||||||
|
});
|
||||||
|
exports["default"] = void 0;
|
||||||
|
var _default = ["BE", "BG", "CZ", "DK", "DE", "EE", "IE", "EL", "ES", "FR", "HR", "IT", "CY", "LV", "LT", "LU", "HU", "MT", "NL", "AT", "PL", "PT", "RO", "SI", "SK", "FI", "SE", "UK"];
|
||||||
|
exports["default"] = _default;
|
||||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,12 @@
|
|||||||
|
export default async (req, res) => {
|
||||||
|
try {
|
||||||
|
const fileService = req.scope.resolve("fileService")
|
||||||
|
|
||||||
|
await fileService.delete(req.body.file)
|
||||||
|
|
||||||
|
res.status(200).send("Deleted image")
|
||||||
|
} catch (err) {
|
||||||
|
console.log(err)
|
||||||
|
throw err
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -15,5 +15,7 @@ export default app => {
|
|||||||
middlewares.wrap(require("./create-upload").default)
|
middlewares.wrap(require("./create-upload").default)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
route.post("/delete", middlewares.wrap(require("./delete-upload").default))
|
||||||
|
|
||||||
return app
|
return app
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user