-
Notifications
You must be signed in to change notification settings - Fork 2
/
webhook.js
29 lines (23 loc) · 874 Bytes
/
webhook.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
const Product = require('./product')
const EVENT_MAP = {
'product.updated': Product.updated,
'product.created': Product.created,
'product.variant.created': Product.variant_created,
'product.variant.updated': Product.variant_updated,
'product.variant.deleted': Product.variant_deleted,
'product.stock_adjusted': Product.stock_adjusted,
}
module.exports.ingest = (event, context, callback) => {
let parsedWebhookBody = JSON.parse(event.body)
EVENT_MAP[parsedWebhookBody.type](parsedWebhookBody.data)
// always return a 200
const response = {
statusCode: 200,
headers: {
'Access-Control-Allow-Origin': '*', // Required for CORS support to work
'Access-Control-Allow-Credentials': true, // Required for cookies, authorization headers with HTTPS
},
body: JSON.stringify({ result: true }),
};
callback(null, response);
};