Events 3.4.0, Accounts 1.4.0, contracts 1.12.0, agent 1.3.0: jobs from the dashboard, styled Accounts emails, .env from the Hub
- Events and Accounts: Background jobs are switched on or off and rescheduled from the admin; the choice is kept in the database (job_overrides), wins over the .env and applies at once. Accounts gets an Admin -> Background jobs page and per-job env flags, as Events. - Accounts: every email styled as Cross Events' (church colour, logo, button, footer), same plain text (src/lib/emails.ts). - Contracts 1.12.0: env-read / env-set agent jobs, envReadResultSchema, isSecretEnvName. - crosscode script: `crosscode env <church> <product>` reads the .env (secrets hidden) and, with --set/--unset/--restart, changes one file, rebuilds the frontend when its file changed, reloads, and puts the file back if the site doesn't answer (lib/envedit.cjs, tests/envedit.bats). - Agent 1.3.0: runs env-read and env-set. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -22,6 +22,8 @@ import { builtInNotice, currentNotice, publish } from '../privacy/notice.js';
|
||||
import { licenceStatus } from '../hub/licence.js';
|
||||
import { connect as connectHub } from '../hub/client.js';
|
||||
import { productName } from '../oidc/clients.js';
|
||||
import { JobError, jobStatus, runNow, setOverride } from '../jobs.js';
|
||||
import { testEmail } from '../lib/emails.js';
|
||||
|
||||
const PAGE = 50;
|
||||
|
||||
@@ -200,7 +202,7 @@ export function adminRouter(ctx: Ctx, provider: Provider) {
|
||||
const me = await admin(req, res);
|
||||
const a = await ctx.db.account.findUniqueOrThrow({ where: { id: me.id } });
|
||||
try {
|
||||
await ctx.messenger.email({ to: a.email, subject: 'Test email from Accounts', text: 'Email from Accounts works.' });
|
||||
await ctx.messenger.email({ to: a.email, ...(await testEmail(ctx)) });
|
||||
} catch (e) {
|
||||
throw new ApiError(502, 'NOT_SENT', `The test email couldn't be sent: ${(e as Error).message}`);
|
||||
}
|
||||
@@ -299,6 +301,36 @@ export function adminRouter(ctx: Ctx, provider: Provider) {
|
||||
}
|
||||
});
|
||||
|
||||
// ─── Background jobs (1.4.0, as Cross Events) ───────────────────────────────
|
||||
|
||||
const jobError = (e: unknown): never => {
|
||||
if (e instanceof JobError) throw new ApiError(e.status, e.status === 404 ? 'NOT_FOUND' : e.status === 400 ? 'VALIDATION' : 'JOB_FAILED', e.message);
|
||||
throw e;
|
||||
};
|
||||
|
||||
r.get('/jobs', handle(async (req, res) => {
|
||||
await admin(req, res);
|
||||
return jobStatus(ctx);
|
||||
}));
|
||||
|
||||
// Switch a job on or off, or change its schedule: wins over the .env; null goes back to it.
|
||||
r.put('/jobs/:name', handle(async (req, res) => {
|
||||
const me = await admin(req, res);
|
||||
const name = String(req.params.name);
|
||||
const change = { enabled: req.body?.enabled, cron: req.body?.cron };
|
||||
const override = await setOverride(ctx, name, change).catch(jobError);
|
||||
await audit(ctx, { actorId: me.id, actorRole: 'admin', action: 'job_settings_changed', targetType: 'job', targetId: name, metadata: change, ip: clientIp(req) });
|
||||
return { name, override };
|
||||
}));
|
||||
|
||||
r.post('/jobs/:name/run', limit(20, 60), handle(async (req, res) => {
|
||||
const me = await admin(req, res);
|
||||
const name = String(req.params.name);
|
||||
const out = await runNow(ctx, name).catch(jobError);
|
||||
await audit(ctx, { actorId: me.id, actorRole: 'admin', action: 'job_run_manual', targetType: 'job', targetId: name, metadata: { queued: out.queued }, ip: clientIp(req) });
|
||||
return out;
|
||||
}));
|
||||
|
||||
// ─── Licence, audit ────────────────────────────────────────────────────────
|
||||
|
||||
r.get('/licence', handle(async (req, res) => {
|
||||
|
||||
Reference in New Issue
Block a user