Clean prepaid SoT, identity mailbox, public access planes, leaf policy, fleet spawn
Some checks are pending
offline / test (push) Waiting to run

Persist account-balance books; edge caches prepaid from books. Add zappier-identity, verae-nats-accounts, verae-jobs-events, verae-access-staff, zapier-decisions. Edge binds loopback; lan-134 stays off; HTTP services prefer local spawn.
This commit is contained in:
George Lambert 2026-09-11 17:15:16 -04:00
commit ddf772454b
81 changed files with 2232 additions and 112 deletions

View file

@ -0,0 +1,3 @@
# NATS — verae-access-staff
Plane `staff`. Authz then billing statement/adjust.

View file

@ -0,0 +1,3 @@
# verae-access-staff
Staff plane for credits and statement review.

View file

@ -0,0 +1,3 @@
# NATS — verae-jobs-events
IN `verae.zapier.jobs.events` queue `jobs-events`.

View file

@ -0,0 +1,3 @@
# verae-jobs-events
Mailbox for `verae.zapier.jobs.events` (passthrough + count).

View file

@ -0,0 +1,3 @@
# NATS — verae-nats-accounts
Policy only. See `policy.json`.

View file

@ -0,0 +1,3 @@
# verae-nats-accounts
INTERNAL vs LEAF. Leaf deny `verae.billing.>`.

View file

@ -0,0 +1,3 @@
# NATS — zapier-decisions
None.

View file

@ -0,0 +1,3 @@
# zapier-decisions
Architecture decisions and action log for the lab cleanup (prepaid SoT, identity, access planes, leaf policy, fleet).

View file

@ -0,0 +1,3 @@
# NATS — zappier-identity
`verae.identity.bind` / `verae.identity.lookup` queue `identity`.

View file

@ -0,0 +1,3 @@
# zappier-identity
Bind and lookup `veraeUserId`. JWTs never stored.

View file

@ -15,15 +15,15 @@ Verae Time proves a SHA-256 existed at a given time. Zapier lets customers regis
| Direct customer API | `verae-access-api` `x-api-key` | HTTPS `:3022` |
| S2S leaf | `verae-access-leaf` | NATS `verae.access.leaf.in` / HTTPS `:3023` |
| Authz | `verae-access-authz` | `verae.access.authz.check` before any internal subject |
| Commercial edge | `zappier-edge` portal, admin, Stripe (legacy combined) | Public HTTPS; NATS billing after authz |
| Commercial edge | `zappier-edge` portal, admin, Stripe | Loopback `:3000`; public doors are access-* |
| Account balance | `zappier-account-balance` prepaid SoT | NATS `verae.billing.*` + HTTP `:3010` |
| CS / sales / accounting | `zappier-customer-service`, `zappier-sales-pricing`, `zappier-accounting-export` | Private HTTP; NATS statement/adjust |
| Middleware HTTP | `/zapier/v1/*` job id + wait | Public HTTPS from edge only |
| Middleware HTTP | `/zapier/v1/*` job id + wait | HTTPS from access-zapier / loopback edge |
| NATS cluster | JetStream subjects under `verae.*` | Private; loopback or SSH tunnel |
| Workers | poller, webhook-deliver, aggregator | NATS + HTTPS to chain or Zapier hooks |
| Archives | WORM + tree nodes | NATS broadcast query; bloom miss = silence |
| Chain | Verae timestamping | HTTPS `api.veraetime.net` or MOCK |
| Control | `verae-fleet` | Operator loopback `:3850`; SSH to extra machines |
| Control | `verae-fleet` | Operator HTTP `:3850` on `0.0.0.0`; SSH to extra machines |
## Request in one sentence

View file

@ -13,6 +13,11 @@ Each runtime piece is its **own git repo** on Forgejo (`git.georgelambert.org`,
| **verae-access-api** | `packages/verae-access-api` | Direct customer API plane (not Zapier) |
| **verae-access-leaf** | `packages/verae-access-leaf` | Server-to-server NATS leaf plane |
| **verae-access-zapier** | `packages/verae-access-zapier` | Zapier Platform plane only |
| **verae-access-staff** | `packages/verae-access-staff` | Staff CS/sales/accounting plane |
| **zappier-identity** | `packages/zappier-identity` | Bind/lookup `veraeUserId` |
| **verae-jobs-events** | `packages/verae-jobs-events` | Mailbox `verae.zapier.jobs.events` |
| **verae-nats-accounts** | `packages/verae-nats-accounts` | INTERNAL vs LEAF subject policy |
| **zapier-decisions** | `packages/zapier-decisions` | Decision log |
| **zappier-account-balance** | `packages/zappier-account-balance` | NATS source of truth for prepaid balances |
| **zappier-customer-service** | `packages/zappier-customer-service` | CS goodwill credits onto prepaid balances |
| **zappier-sales-pricing** | `packages/zappier-sales-pricing` | Sales per-customer tier / multiplier |

View file

@ -54,7 +54,7 @@ Operator console (loopback): http://127.0.0.1:3850/ · [CONSOLE.pdf](https://zap
Prefix: `https://git.georgelambert.org/marchon/`
overview · verae-nats-process · verae-ops · master-zapier-plan-draft · zappier-edge · verae-access-authz · verae-access-web · verae-access-api · verae-access-leaf · verae-access-zapier · verae-middleware · verae-zapier-app · verae-activate · verae-request-splitter · verae-archive-worm · verae-archive-aggregator · verae-tree-node · verae-fleet · verae-zapier-simulator · zapier-user-docs · zapier-docs-master
overview · verae-nats-process · verae-ops · master-zapier-plan-draft · zappier-edge · verae-access-authz · verae-access-web · verae-access-api · verae-access-leaf · verae-access-zapier · verae-access-staff · zappier-identity · verae-jobs-events · verae-nats-accounts · zapier-decisions · verae-middleware · verae-zapier-app · verae-activate · verae-request-splitter · verae-archive-worm · verae-archive-aggregator · verae-tree-node · verae-fleet · verae-zapier-simulator · zapier-user-docs · zapier-docs-master
## Per-module contracts

View file

@ -0,0 +1,28 @@
import fs from 'node:fs';
const FALLBACK = [
'verae.archive.put',
'verae.archive.query',
'verae.archive.reply.',
'verae.zapier.jobs.watch',
'verae.zapier.jobs.events',
'verae.zapier.webhooks.deliver',
];
export function leafAllowList() {
const p = process.env.NATS_POLICY_PATH;
if (p && fs.existsSync(p)) {
try {
return JSON.parse(fs.readFileSync(p, 'utf8')).leafAllow || FALLBACK;
} catch {
return FALLBACK;
}
}
return FALLBACK;
}
export function leafAllowed(subject) {
return leafAllowList().some((p) =>
p.endsWith('.') ? subject.startsWith(p) : subject === p || subject.startsWith(`${p}.`),
);
}

View file

@ -5,6 +5,7 @@
* then forwards only allowed internal subjects (archive + jobs, never billing).
*/
import http from 'node:http';
import { leafAllowed } from './allow.js';
const PORT = Number(process.env.PORT || 3023);
const AUTHZ = (process.env.AUTHZ_URL || 'http://127.0.0.1:3020').replace(/\/$/, '');
@ -30,6 +31,9 @@ async function forward(body) {
return { status: 401, body: { allow: false, reason: 'bad leaf token' } };
}
const target = body.target || body.subject;
if (!leafAllowed(target)) {
return { status: 403, body: { allow: false, reason: `leaf policy denies ${target}` } };
}
const gate = await check(target, body.principal || 'leaf');
if (!gate.allow) return { status: 403, body: gate };
const url = process.env.NATS_URL;

View file

@ -0,0 +1,3 @@
# NATS — verae-access-staff
Plane `staff`. Authz then `verae.billing.statement.get` / `balance.adjust`.

View file

@ -0,0 +1,7 @@
# verae-access-staff
Staff access plane for CS / sales / accounting. Credits and statement review after `verae.access.authz.check` with plane `staff`.
**Forgejo:** https://git.georgelambert.org/marchon/verae-access-staff
Port `:3025`.

View file

@ -0,0 +1,11 @@
{
"name": "verae-access-staff",
"version": "0.1.0",
"private": true,
"type": "module",
"description": "Staff access plane (CS/sales/accounting)",
"scripts": {
"start": "node src/server.js",
"test": "node --test test/*.test.js"
}
}

View file

@ -0,0 +1,57 @@
#!/usr/bin/env node
/** Staff access plane (CS / sales / accounting). Not Zapier, not customer API. */
import http from 'node:http';
const PORT = Number(process.env.PORT || 3025);
const AUTHZ = (process.env.AUTHZ_URL || 'http://127.0.0.1:3020').replace(/\/$/, '');
const BOOKS = (process.env.ACCOUNT_BALANCE_URL || 'http://127.0.0.1:3010').replace(/\/$/, '');
const PLANE = 'staff';
async function check(subject, extra = {}) {
const r = await fetch(`${AUTHZ}/check`, {
method: 'POST',
headers: { 'content-type': 'application/json' },
body: JSON.stringify({ plane: PLANE, subject, ...extra }),
});
return r.json();
}
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: 'verae-access-staff', plane: PLANE });
}
const review = url.pathname.match(/^\/review\/([^/]+)$/);
if (req.method === 'GET' && review) {
const gate = await check('verae.billing.statement.get', { principal: review[1] });
if (!gate.allow) return json(403, gate);
const r = await fetch(`${BOOKS}/statement/${review[1]}`);
return json(r.status, { ...(await r.json()), plane: PLANE, source: 'account-balance' });
}
if (req.method === 'POST' && url.pathname === '/credits') {
const chunks = [];
for await (const c of req) chunks.push(c);
const body = JSON.parse(Buffer.concat(chunks).toString('utf8') || '{}');
const gate = await check('verae.billing.balance.adjust', { kind: 'credit', principal: body.agent });
if (!gate.allow) return json(403, gate);
const r = await fetch(`${BOOKS}/adjust`, {
method: 'POST',
headers: { 'content-type': 'application/json' },
body: JSON.stringify({ ...body, kind: 'credit' }),
});
return json(r.status, { ...(await r.json()), plane: PLANE });
}
json(404, { error: 'not found' });
} catch (err) {
json(502, { error: err.message });
}
});
server.listen(PORT, '0.0.0.0', () => {
process.stdout.write(`verae-access-staff http://0.0.0.0:${PORT}/ plane=${PLANE}\n`);
});

View file

@ -0,0 +1,56 @@
import { test } from 'node:test';
import assert from 'node:assert/strict';
import { spawn } from 'node:child_process';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
const root = path.join(path.dirname(fileURLToPath(import.meta.url)), '..');
const authzRoot = path.join(root, '..', 'verae-access-authz');
const booksRoot = path.join(root, '..', 'zappier-account-balance');
test('staff plane can credit after authz; zapier cannot', async () => {
const authzPort = 18031;
const booksPort = 18032;
const staffPort = 18033;
const authz = spawn(process.execPath, ['src/server.js'], {
cwd: authzRoot,
env: { ...process.env, PORT: String(authzPort) },
stdio: ['ignore', 'pipe', 'pipe'],
});
const books = spawn(process.execPath, ['src/server.js'], {
cwd: booksRoot,
env: { ...process.env, PORT: String(booksPort), BOOKS_PATH: `/tmp/staff-books-${Date.now()}.json` },
stdio: ['ignore', 'pipe', 'pipe'],
});
const staff = spawn(process.execPath, ['src/server.js'], {
cwd: root,
env: {
...process.env,
PORT: String(staffPort),
AUTHZ_URL: `http://127.0.0.1:${authzPort}`,
ACCOUNT_BALANCE_URL: `http://127.0.0.1:${booksPort}`,
},
stdio: ['ignore', 'pipe', 'pipe'],
});
await new Promise((r) => setTimeout(r, 600));
try {
const h = await (await fetch(`http://127.0.0.1:${staffPort}/health`)).json();
assert.equal(h.plane, 'staff');
const add = await fetch(`http://127.0.0.1:${staffPort}/credits`, {
method: 'POST',
headers: { 'content-type': 'application/json' },
body: JSON.stringify({ customerId: 'c-staff', cents: 50, reason: 'test', agent: 'cs' }),
});
assert.equal(add.status, 200);
const deny = await fetch(`http://127.0.0.1:${authzPort}/check`, {
method: 'POST',
headers: { 'content-type': 'application/json' },
body: JSON.stringify({ plane: 'zapier', subject: 'verae.billing.balance.adjust' }),
});
assert.equal(deny.status, 403);
} finally {
staff.kill('SIGTERM');
books.kill('SIGTERM');
authz.kill('SIGTERM');
}
});

Some files were not shown because too many files have changed in this diff Show more