Release events@2.2.0 and contracts@1.2.0

Events 2.2.0: the move into the monorepo and the crosscode script, plus
AI use in tokens and the backend under /api. Contracts 1.2.0: token
fields on the AI status. Agent phase 1d moves to contracts 1.3.0.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-17 11:38:09 +02:00
co-authored by Claude Opus 5.5
parent a0ab22fbf3
commit 53e15fdd69
25 changed files with 63 additions and 45 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@crosscode/events-backend",
"version": "2.1.1",
"version": "2.2.0",
"description": "Event Management System Backend",
"main": "src/index.js",
"scripts": {
@@ -1,3 +1,3 @@
-- 2.3.0: tokens per AI call, which is what the site shows (the rand amount is the Hub's business).
-- 2.2.0: tokens per AI call, which is what the site shows (the rand amount is the Hub's business).
ALTER TABLE "AiCall" ADD COLUMN "inputTokens" INTEGER NOT NULL DEFAULT 0;
ALTER TABLE "AiCall" ADD COLUMN "outputTokens" INTEGER NOT NULL DEFAULT 0;
+2 -2
View File
@@ -2342,9 +2342,9 @@ model AiCall {
// ok, refused, incomplete, failed, cap_reached, unavailable
outcome String
// What the church was charged, in cents (fractions of a cent). Kept for the record; the site
// shows tokens (2.3.0), and only the Hub shows rand.
// shows tokens (2.2.0), and only the Hub shows rand.
chargedCents Float @default(0)
// Tokens the call used (2.3.0): input counts cached prompt tokens. 0 when the call failed.
// Tokens the call used (2.2.0): input counts cached prompt tokens. 0 when the call failed.
inputTokens Int @default(0)
outputTokens Int @default(0)
createdAt DateTime @default(now())
+2 -2
View File
@@ -1,7 +1,7 @@
/**
* AI helpers (2.0, roadmap §15). The site never holds a Claude API key: every call goes through
* the Cross Events Hub (docs/hub-protocol.md §3b), which checks the licence's monthly cap, calls
* Claude and meters the call. The site shows that use as tokens and a percentage (2.3.0); the cap's
* Claude and meters the call. The site shows that use as tokens and a percentage (2.2.0); the cap's
* rand amount stays on the Hub. This module:
* - works out what the AI buttons do (`aiStatus`): hidden, working, or disabled until the
* allowance renews — from the licence token first, then the Hub (cached for a minute);
@@ -35,7 +35,7 @@ export type HelperName = (typeof HELPERS)[number];
/**
* What the Hub says (§3b), as the site keeps it. The Hub also sends the allowance in rand
* (`capCents`, `usedCents`); the site drops those (2.3.0): people see tokens and a percentage,
* (`capCents`, `usedCents`); the site drops those (2.2.0): people see tokens and a percentage,
* and only the Hub shows rand. The token fields are null from a Hub before 2.0.1.
*/
export type HubAiStatus = {
+4 -4
View File
@@ -153,7 +153,7 @@ app.use((req, res, next) => {
// Licence suspended, revoked or missing: no new or edited events, registrations or payments (src/hub/readOnly.js).
app.use(require('./hub/readOnly').licenceReadOnly);
// Everything the backend serves is under /api (2.3.0), so the site and its API can share one
// Everything the backend serves is under /api (2.2.0), so the site and its API can share one
// address: the web server sends /api to the backend and everything else to the frontend. The old
// paths (/, /health, /docs/v2, /uploads) still work for sites with a separate API address.
@@ -180,7 +180,7 @@ app.use('/api/v2', require('./v2').v2Router());
app.use(legacyLinkRedirects);
app.use('/api/docs/v2', require('./v2').v2DocsRouter());
app.get('/api/docs', (req, res) => res.redirect(301, '/api/docs/v2'));
// Before 2.3.0 the reference was at /docs/v2 (bookmarks, the old status page).
// Before 2.2.0 the reference was at /docs/v2 (bookmarks, the old status page).
app.use('/docs/v2', (req, res) => res.redirect(301, `/api${req.originalUrl}`));
app.get('/docs', (req, res) => res.redirect(301, '/api/docs/v2'));
@@ -192,7 +192,7 @@ warmCache().catch(() => {});
// in the site's origin if opened directly, so pin the safe response headers
// (no inline execution, no MIME-sniffing to HTML/script) on every asset here.
// Stored paths stay "/uploads/…"; they're given out as /api/uploads/… (v2/schemas.ts absoluteUrl).
// /uploads still answers for links made before 2.3.0.
// /uploads still answers for links made before 2.2.0.
const uploads = express.static('public/uploads', {
setHeaders: (res) => {
res.setHeader('Content-Security-Policy', "default-src 'none'; style-src 'unsafe-inline'; sandbox");
@@ -276,7 +276,7 @@ app.get('/favicon.ico', (req, res) => {
res.sendFile(path.join(__dirname, '..', 'src', 'favicon.ico'));
});
// ── Status page, at /api (2.3.0); / sends you there ─────────────────────────
// ── Status page, at /api (2.2.0); / sends you there ─────────────────────────
app.get('/', (req, res) => res.redirect(302, '/api'));
app.get('/api', async (req, res) => {
const mem = process.memoryUsage();
@@ -46,7 +46,7 @@ function toAbsoluteUrl(req, url) {
return raw; // keep as-is if already absolute and not localhost
}
// Relative path like /uploads/... => prefix with request origin; uploads are served under
// /api/uploads (2.3.0) so they reach the backend when the site and API share one address
// /api/uploads (2.2.0) so they reach the backend when the site and API share one address
if (raw.startsWith('/')) {
return `${req.protocol}://${req.get('host')}${raw.startsWith('/uploads/') ? `/api${raw}` : raw}`;
}
+1 -1
View File
@@ -43,7 +43,7 @@ export function v2Router(): Router {
}
/**
* /api/docs/v2 (2.3.0; /docs/v2 before, which now redirects): Swagger UI (served from swagger-ui-dist, nothing from a CDN). The page itself is
* /api/docs/v2 (2.2.0; /docs/v2 before, which now redirects): Swagger UI (served from swagger-ui-dist, nothing from a CDN). The page itself is
* public; it asks for an admin token and uses it to load openapi.json and to try requests.
*/
export function v2DocsRouter(): Router {
+1 -1
View File
@@ -15,7 +15,7 @@ export function iso(d: Date | string | null | undefined): string | null {
}
/**
* Where a stored upload path is served: "/uploads/…" (as stored) → "/api/uploads/…" (2.3.0), so it
* Where a stored upload path is served: "/uploads/…" (as stored) → "/api/uploads/…" (2.2.0), so it
* reaches the backend when the site and its API share one address. Anything else is unchanged.
*/
export function uploadPath(raw: string): string {
+1 -1
View File
@@ -72,7 +72,7 @@ describe('status', () => {
expect(await aiStatus()).toMatchObject({ enabled: true, available: false });
});
test('the Hub\'s rand amounts never leave the site (2.3.0); a Hub before 2.0.1 sends no tokens', async () => {
test('the Hub\'s rand amounts never leave the site (2.2.0); a Hub before 2.0.1 sends no tokens', async () => {
mockPost.mockResolvedValueOnce(hubStatus());
const s = await aiStatus() as unknown as Record<string, unknown>;
expect(s).not.toHaveProperty('capCents');
+1 -1
View File
@@ -558,7 +558,7 @@ describe('sections, costs, image uploads', () => {
expect(res.body.data.url).toMatch(/^http:\/\/[^/]+\/api\/uploads\/events\/event-123\.jpg$/);
});
test('stored uploads are given out under /api/uploads (2.3.0); other addresses are left alone', () => {
test('stored uploads are given out under /api/uploads (2.2.0); other addresses are left alone', () => {
expect(uploadPath('/uploads/branding/logo.png')).toBe('/api/uploads/branding/logo.png');
expect(uploadPath('/api/uploads/x.png')).toBe('/api/uploads/x.png');
expect(uploadPath('/images/x.png')).toBe('/images/x.png');