Wire zappier-edge into the live stack and add billing department APIs
Some checks are pending
offline / test (push) Waiting to run

Fleet now spawns the real zappier and middleware processes. Metered
timestamp/receipt/hash calls proxy to middleware when ZAPPIER_UPSTREAM
is set. CS credits, sales per-customer pricing, and QuickBooks export
are separate repos plugged into zappier-edge admin.
This commit is contained in:
George Lambert 2026-09-11 15:15:55 -04:00
parent 65bfa544b2
commit a1a5b957fd
44 changed files with 822 additions and 18 deletions

View file

@ -0,0 +1,42 @@
#!/usr/bin/env node
/** Accounting department: QuickBooks IIF + CSV from zappier-edge invoices. */
import http from 'node:http';
const PORT = Number(process.env.PORT || 3013);
const EDGE = (process.env.ZAPPIER_ADMIN_URL || 'http://127.0.0.1:3000').replace(/\/$/, '');
const KEY = process.env.ZAPPIER_ADMIN_KEY || 'admin-dev-key';
async function edge(pathname) {
const r = await fetch(`${EDGE}${pathname}`, { headers: { 'x-admin-key': KEY } });
return r;
}
const server = http.createServer(async (req, res) => {
const url = new URL(req.url || '/', `http://127.0.0.1:${PORT}`);
const send = (code, type, body) => {
res.writeHead(code, { 'content-type': type });
res.end(body);
};
try {
if (req.method === 'GET' && url.pathname === '/health') {
return send(200, 'application/json', JSON.stringify({ ok: true, role: 'zappier-accounting-export' }));
}
const period = url.searchParams.get('period');
const q = period ? `?period=${encodeURIComponent(period)}` : '';
if (req.method === 'GET' && url.pathname === '/export/quickbooks.iif') {
const r = await edge(`/admin/api/exports/quickbooks.iif${q}`);
return send(r.status, 'text/plain', await r.text());
}
if (req.method === 'GET' && url.pathname === '/export/accounting.csv') {
const r = await edge(`/admin/api/exports/accounting.csv${q}`);
return send(r.status, 'text/csv', await r.text());
}
send(404, 'application/json', JSON.stringify({ error: 'not found' }));
} catch (err) {
send(502, 'application/json', JSON.stringify({ error: err.message }));
}
});
server.listen(PORT, '0.0.0.0', () => {
process.stdout.write(`zappier-accounting-export http://127.0.0.1:${PORT}/\n`);
});