- A site the Hub answers INSTALL_NOT_FOUND for drops its install and licence, so it no longer shows "Active" on the old token. - Unlicensed is read-only like suspended; read-only also blocks editing events, options and variants. LICENCE_CHECK_DISABLED (ignored in production) for e2e. - Heartbeat 30 s after the server starts and after a licence key is connected. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
55 lines
2.5 KiB
JavaScript
55 lines
2.5 KiB
JavaScript
/**
|
|
* Read-only mode while the licence is suspended, revoked or missing (not connected to the Hub):
|
|
* no new or edited events, and no *new* activity — registrations, tickets added, payments started
|
|
* or recorded, waitlist places, coupons or bundles.
|
|
* Everything else keeps working on purpose: scanning tickets for events people already paid for,
|
|
* viewing and exporting data, refunds and cancellations, privacy requests, logging in, and the
|
|
* settings needed to renew the licence. Payment webhooks for payments already started also still
|
|
* arrive (they're mounted before this middleware).
|
|
*/
|
|
|
|
const { licenceStatus } = require('./licence');
|
|
|
|
const BLOCKED = [
|
|
['POST', /^\/api\/events\/?$/],
|
|
['PUT', /^\/api\/events\/[^/]+\/?$/],
|
|
['POST', /^\/api\/events\/[^/]+\/options\/?$/],
|
|
['PUT', /^\/api\/events\/options\/[^/]+\/?$/],
|
|
['POST', /^\/api\/events\/options\/[^/]+\/variants\/?$/],
|
|
['PUT', /^\/api\/events\/variants\/[^/]+\/?$/],
|
|
['POST', /^\/api\/registrations\/?$/],
|
|
['POST', /^\/api\/registrations\/manual\/?$/],
|
|
['PUT', /^\/api\/registrations\/[^/]+\/options\/?$/],
|
|
['POST', /^\/api\/payments\/?$/],
|
|
['POST', /^\/api\/payments\/(checkout|yoco-checkout)(\/send)?\/?$/],
|
|
['POST', /^\/api\/payments\/pay\/[^/]+\/?$/],
|
|
['POST', /^\/api\/waitlist\/?$/],
|
|
['POST', /^\/api\/coupons\/?$/],
|
|
['POST', /^\/api\/bundles\/event\/[^/]+\/?$/],
|
|
];
|
|
|
|
function isBlocked(method, path) {
|
|
return BLOCKED.some(([m, re]) => m === method && re.test(path));
|
|
}
|
|
|
|
async function licenceReadOnly(req, res, next) {
|
|
if (!isBlocked(req.method, req.path)) return next();
|
|
try {
|
|
const status = await licenceStatus();
|
|
if (!status.readOnly) return next();
|
|
return res.status(403).json({
|
|
code: 'LICENCE_READ_ONLY',
|
|
message: status.state === 'revoked'
|
|
? "This site's licence has been revoked, so nothing new can be added and events can't be changed. Tickets still scan and all data can still be viewed and exported."
|
|
: status.state === 'unlicensed'
|
|
? "This site has no licence, so nothing new can be added and events can't be changed. A site admin can connect a licence key in Site settings → Licence."
|
|
: "This site's licence is suspended, so nothing new can be added and events can't be changed for now. Tickets still scan and all data can still be viewed and exported. Please contact the site's administrator.",
|
|
});
|
|
} catch {
|
|
// Never let a licence check failure take the site down.
|
|
return next();
|
|
}
|
|
}
|
|
|
|
module.exports = { licenceReadOnly, isBlocked, BLOCKED };
|