feat: add Business Central CPNP sync and expand history access

- Add bc-proxy and bc-export serverless API handlers
- Add businessCentral service with updateCpnpNoInBC and downloadBusinessCentralItemsExcel
- Sync cpnpNo to BC on save (CosmeticItemsView and handleSaveAll)
- Parallelize handleSaveAll with Promise.all
- Fix array index key, a11y click/keyboard handlers, autoFocus
- Grant Change History and Pending Validation access to jingying.shi@craze-group.com

Co-Authored-By: claude-flow <ruv@ruv.net>
This commit is contained in:
Christian Vidal Wolf
2026-05-14 17:17:10 +02:00
co-authored by claude-flow
parent 2961d3f86a
commit 9b5932920e
11 changed files with 585 additions and 19 deletions
+49
View File
@@ -0,0 +1,49 @@
import { getBcConfig, getBCToken, findItem, patchItemCpnpNo } from '../bc-runtime.js';
const ALLOWED_ORIGINS = [
'http://localhost:3000',
'http://localhost:4173',
'http://localhost:5173',
'https://craze-data-check.vercel.app',
];
function setCors(req, res) {
const origin = req.headers.origin;
if (origin && ALLOWED_ORIGINS.includes(origin)) {
res.setHeader('Access-Control-Allow-Origin', origin);
}
res.setHeader('Access-Control-Allow-Methods', 'POST, OPTIONS');
res.setHeader('Access-Control-Allow-Headers', 'Content-Type');
res.setHeader('Vary', 'Origin');
}
export default async function handler(req, res) {
setCors(req, res);
if (req.method === 'OPTIONS') return res.status(204).end();
const origin = req.headers.origin;
if (origin && !ALLOWED_ORIGINS.includes(origin)) {
return res.status(403).json({ error: 'Forbidden' });
}
if (req.method !== 'POST') {
return res.status(405).json({ error: 'Method not allowed' });
}
const { articleNo, cpnpNo } = req.body || {};
if (!articleNo || cpnpNo === undefined) {
return res.status(400).json({ error: 'Missing articleNo or cpnpNo' });
}
try {
const config = getBcConfig();
const token = await getBCToken(config);
const item = await findItem(config, token, articleNo);
await patchItemCpnpNo(config, token, item, String(cpnpNo));
return res.json({ success: true, articleNo, cpnpNo });
} catch (err) {
console.error('[bc-proxy] error:', err.message);
return res.status(500).json({ success: false, error: err.message });
}
}