Clean prepaid SoT, identity mailbox, public access planes, leaf policy, fleet spawn
Some checks are pending
offline / test (push) Waiting to run
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:
parent
345aeeead9
commit
ddf772454b
81 changed files with 2232 additions and 112 deletions
3
packages/docs-master/modules/verae-access-staff/NATS.md
Normal file
3
packages/docs-master/modules/verae-access-staff/NATS.md
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
# NATS — verae-access-staff
|
||||
|
||||
Plane `staff`. Authz then billing statement/adjust.
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
# verae-access-staff
|
||||
|
||||
Staff plane for credits and statement review.
|
||||
3
packages/docs-master/modules/verae-jobs-events/NATS.md
Normal file
3
packages/docs-master/modules/verae-jobs-events/NATS.md
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
# NATS — verae-jobs-events
|
||||
|
||||
IN `verae.zapier.jobs.events` queue `jobs-events`.
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
# verae-jobs-events
|
||||
|
||||
Mailbox for `verae.zapier.jobs.events` (passthrough + count).
|
||||
3
packages/docs-master/modules/verae-nats-accounts/NATS.md
Normal file
3
packages/docs-master/modules/verae-nats-accounts/NATS.md
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
# NATS — verae-nats-accounts
|
||||
|
||||
Policy only. See `policy.json`.
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
# verae-nats-accounts
|
||||
|
||||
INTERNAL vs LEAF. Leaf deny `verae.billing.>`.
|
||||
3
packages/docs-master/modules/zapier-decisions/NATS.md
Normal file
3
packages/docs-master/modules/zapier-decisions/NATS.md
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
# NATS — zapier-decisions
|
||||
|
||||
None.
|
||||
3
packages/docs-master/modules/zapier-decisions/SUMMARY.md
Normal file
3
packages/docs-master/modules/zapier-decisions/SUMMARY.md
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
# zapier-decisions
|
||||
|
||||
Architecture decisions and action log for the lab cleanup (prepaid SoT, identity, access planes, leaf policy, fleet).
|
||||
3
packages/docs-master/modules/zappier-identity/NATS.md
Normal file
3
packages/docs-master/modules/zappier-identity/NATS.md
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
# NATS — zappier-identity
|
||||
|
||||
`verae.identity.bind` / `verae.identity.lookup` queue `identity`.
|
||||
3
packages/docs-master/modules/zappier-identity/SUMMARY.md
Normal file
3
packages/docs-master/modules/zappier-identity/SUMMARY.md
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
# zappier-identity
|
||||
|
||||
Bind and lookup `veraeUserId`. JWTs never stored.
|
||||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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 |
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
28
packages/verae-access-leaf/src/allow.js
Normal file
28
packages/verae-access-leaf/src/allow.js
Normal 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}.`),
|
||||
);
|
||||
}
|
||||
|
|
@ -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;
|
||||
|
|
|
|||
3
packages/verae-access-staff/NATS.md
Normal file
3
packages/verae-access-staff/NATS.md
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
# NATS — verae-access-staff
|
||||
|
||||
Plane `staff`. Authz then `verae.billing.statement.get` / `balance.adjust`.
|
||||
7
packages/verae-access-staff/README.md
Normal file
7
packages/verae-access-staff/README.md
Normal 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`.
|
||||
11
packages/verae-access-staff/package.json
Normal file
11
packages/verae-access-staff/package.json
Normal 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"
|
||||
}
|
||||
}
|
||||
57
packages/verae-access-staff/src/server.js
Normal file
57
packages/verae-access-staff/src/server.js
Normal 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`);
|
||||
});
|
||||
56
packages/verae-access-staff/test/health.test.js
Normal file
56
packages/verae-access-staff/test/health.test.js
Normal 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
Loading…
Reference in a new issue