- Express 5 (qs query parser and req.body = {} kept as in Express 4).
- Scanner and at-the-door check-in use /api/v2/checkin; look-up gives attendee, bookedBy,
ticketOptionId.
- Shared middleware errors on /api/v2 rewritten to { error: { code, message, reason } };
apiFetch treats reason like v1's code.
- Deprecation + Link: rel="successor-version" on v1 endpoints that have a v2 replacement.
- Roadmap: open question on how much of v1 to retire in 2.0.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Ls1vMdg2GYqbnKZmPaX1ot
53 lines
2.5 KiB
TypeScript
53 lines
2.5 KiB
TypeScript
import type { RequestHandler } from 'express';
|
|
|
|
/**
|
|
* v1 endpoints that have a v2 replacement say so (1.51.3): a `Deprecation` header (RFC 9745,
|
|
* the date v2 covered them) and `Link: <…>; rel="successor-version"` pointing at the v2
|
|
* endpoint. v1 keeps working until 2.0; endpoints without a v2 version get no header yet.
|
|
*/
|
|
|
|
// When these v1 endpoints got their v2 replacement (1.51.3's release day).
|
|
const DEPRECATED_AT = Math.floor(Date.UTC(2026, 9, 29) / 1000);
|
|
|
|
type Successor = { method: string; v1: RegExp; v2: (m: RegExpMatchArray) => string };
|
|
|
|
const SUCCESSORS: Successor[] = [
|
|
{ method: 'GET', v1: /^\/api\/events\/?$/, v2: () => '/api/v2/events' },
|
|
{ method: 'GET', v1: /^\/api\/events\/([^/]+)$/, v2: m => `/api/v2/events/${m[1]}` },
|
|
{ method: 'GET', v1: /^\/api\/users\/profile$/, v2: () => '/api/v2/me' },
|
|
{ method: 'PUT', v1: /^\/api\/users\/profile$/, v2: () => '/api/v2/me' },
|
|
{ method: 'POST', v1: /^\/api\/users\/?$/, v2: () => '/api/v2/auth/signup' },
|
|
{ method: 'POST', v1: /^\/api\/users\/login$/, v2: () => '/api/v2/auth/login' },
|
|
{ method: 'POST', v1: /^\/api\/users\/login\/2fa$/, v2: () => '/api/v2/auth/login/code' },
|
|
{ method: 'GET', v1: /^\/api\/registrations\/myregistrations$/, v2: () => '/api/v2/me/registrations' },
|
|
{ method: 'POST', v1: /^\/api\/registrations\/?$/, v2: () => '/api/v2/registrations' },
|
|
{ method: 'DELETE', v1: /^\/api\/registrations\/([^/]+)$/, v2: m => `/api/v2/registrations/${m[1]}/cancel` },
|
|
{ method: 'POST', v1: /^\/api\/payments\/checkout$/, v2: () => '/api/v2/registrations/{id}/checkout' },
|
|
{ method: 'GET', v1: /^\/api\/tickets\/scan-preview\/([^/]+)$/, v2: m => `/api/v2/checkin/${m[1]}` },
|
|
{ method: 'POST', v1: /^\/api\/tickets\/scan\/([^/]+)$/, v2: m => `/api/v2/checkin/${m[1]}` },
|
|
];
|
|
|
|
// GET /api/events/all isn't a single event.
|
|
const NOT_AN_EVENT_ID = new Set(['all']);
|
|
|
|
/** The v2 successor of a v1 request, if it has one. Pure; exported for tests. */
|
|
export function successorOf(method: string, path: string): string | null {
|
|
for (const s of SUCCESSORS) {
|
|
if (s.method !== method) continue;
|
|
const m = path.match(s.v1);
|
|
if (!m) continue;
|
|
if (s.v1.source.startsWith('^\\/api\\/events\\/(') && NOT_AN_EVENT_ID.has(m[1])) continue;
|
|
return s.v2(m);
|
|
}
|
|
return null;
|
|
}
|
|
|
|
export const deprecationHeaders: RequestHandler = (req, res, next) => {
|
|
const successor = successorOf(req.method, req.originalUrl.split('?')[0]);
|
|
if (successor) {
|
|
res.setHeader('Deprecation', `@${DEPRECATED_AT}`);
|
|
res.setHeader('Link', `<${successor}>; rel="successor-version"`);
|
|
}
|
|
next();
|
|
};
|