Add native Olist composition sync
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 1m24s

This commit is contained in:
Cauê Faleiros
2026-08-10 11:26:38 -03:00
parent e85dbe6f10
commit 1a430d4fb0
12 changed files with 669 additions and 5 deletions

View File

@@ -0,0 +1,55 @@
const express = require('express');
const { verifySuperAdmin } = require('../auth');
const {
completeAuthorization,
createAuthorizationUrl,
getOlistFrontendRedirect,
getOlistStatus,
startOlistSync
} = require('../services/olistService');
const router = express.Router();
router.get('/olist/status', verifySuperAdmin, async (req, res, next) => {
try {
res.json(await getOlistStatus());
} catch (error) {
next(error);
}
});
router.post('/olist/authorization-url', verifySuperAdmin, async (req, res, next) => {
try {
res.json({ url: await createAuthorizationUrl() });
} catch (error) {
next(error);
}
});
router.post('/olist/sync', verifySuperAdmin, async (req, res, next) => {
try {
const result = await startOlistSync({
trigger: 'manual',
fullSync: req.body?.fullSync === true
});
res.status(result.accepted ? 202 : 409).json(result);
} catch (error) {
next(error);
}
});
router.get('/olist/oauth/callback', async (req, res) => {
try {
if (req.query.error || !req.query.code || !req.query.state) {
res.redirect(getOlistFrontendRedirect('cancelled'));
return;
}
await completeAuthorization({ code: String(req.query.code), state: String(req.query.state) });
res.redirect(getOlistFrontendRedirect('connected'));
} catch (error) {
console.error('Olist OAuth callback failed:', error.message);
res.redirect(getOlistFrontendRedirect('failed'));
}
});
module.exports = router;