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,14 @@
# zappier-sales-pricing
Sales-department API for **per-customer pricing** (tier + `multiplierOverride`). zappier-edge remains the rate-card store.
**Forgejo:** https://git.georgelambert.org/marchon/zappier-sales-pricing
**Catalog:** https://zapier.georgelambert.org/packages/zappier-sales-pricing/README.pdf
```bash
PORT=3012 node src/server.js
curl http://127.0.0.1:3012/quotes/cust_2
curl -X PUT http://127.0.0.1:3012/customers/cust_2/pricing \
-H 'content-type: application/json' \
-d '{"multiplierOverride":0.4,"tierId":"business"}'
```

View file

@ -0,0 +1,11 @@
{
"name": "zappier-sales-pricing",
"version": "0.1.0",
"private": true,
"type": "module",
"description": "Sales-department per-customer pricing; writes multiplier/tier on zappier-edge",
"scripts": {
"start": "node src/server.js",
"test": "node --test test/*.test.js"
}
}

View file

@ -0,0 +1,54 @@
#!/usr/bin/env node
/** Sales department: per-customer multiplier / tier. Writes through zappier-edge. */
import http from 'node:http';
const PORT = Number(process.env.PORT || 3012);
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, { method = 'GET', body } = {}) {
const r = await fetch(`${EDGE}${pathname}`, {
method,
headers: { 'content-type': 'application/json', 'x-admin-key': KEY },
body: body ? JSON.stringify(body) : undefined,
});
const text = await r.text();
try {
return { status: r.status, body: JSON.parse(text) };
} catch {
return { status: r.status, body: text };
}
}
const server = http.createServer(async (req, res) => {
const url = new URL(req.url || '/', `http://127.0.0.1:${PORT}`);
const json = (code, obj) => {
res.writeHead(code, { 'content-type': 'application/json' });
res.end(JSON.stringify(obj));
};
try {
if (req.method === 'GET' && url.pathname === '/health') {
return json(200, { ok: true, role: 'zappier-sales-pricing' });
}
const quote = url.pathname.match(/^\/quotes\/([^/]+)$/);
if (req.method === 'GET' && quote) {
const forwarded = await edge(`/admin/api/sales/quote/${quote[1]}`);
return json(forwarded.status, forwarded.body);
}
const price = url.pathname.match(/^\/customers\/([^/]+)\/pricing$/);
if (req.method === 'PUT' && price) {
const chunks = [];
for await (const c of req) chunks.push(c);
const payload = JSON.parse(Buffer.concat(chunks).toString('utf8') || '{}');
const forwarded = await edge(`/admin/api/customers/${price[1]}`, { method: 'PUT', body: payload });
return json(forwarded.status, forwarded.body);
}
json(404, { error: 'not found' });
} catch (err) {
json(502, { error: err.message });
}
});
server.listen(PORT, '0.0.0.0', () => {
process.stdout.write(`zappier-sales-pricing http://127.0.0.1:${PORT}/\n`);
});

View file

@ -0,0 +1,23 @@
import { test } from 'node:test';
import assert from 'node:assert/strict';
import { spawn } from 'node:child_process';
import { fileURLToPath } from 'node:url';
import path from 'node:path';
const root = path.join(path.dirname(fileURLToPath(import.meta.url)), '..');
test('sales-pricing health', async () => {
const port = 18012;
const child = spawn(process.execPath, ['src/server.js'], {
cwd: root,
env: { ...process.env, PORT: String(port) },
stdio: ['ignore', 'pipe', 'pipe'],
});
await new Promise((r) => setTimeout(r, 400));
try {
const r = await fetch(`http://127.0.0.1:${port}/health`);
assert.equal((await r.json()).role, 'zappier-sales-pricing');
} finally {
child.kill('SIGTERM');
}
});