Server-Side Usage
const { LuneoClient } = require('@luneo/sdk');
const client = new LuneoClient({
apiKey: process.env.LUNEO_API_KEY
});
// Express route
app.post('/api/create-design', async (req, res) => {
const design = await client.designs.create({
product_id: req.body.productId,
canvas_data: req.body.canvasData
});
res.json({ design });
});Webhooks
// Webhook verification
const crypto = require('crypto');
app.post('/webhooks/luneo', (req, res) => {
const signature = req.headers['x-luneo-signature'];
const payload = JSON.stringify(req.body);
const hash = crypto
.createHmac('sha256', process.env.WEBHOOK_SECRET)
.update(payload)
.digest('hex');
if (hash !== signature) {
return res.status(401).send('Invalid');
}
logger.info('Event:', req.body.type);
res.json({ ok: true });
});