Events 3.1.0, Accounts 1.2.0, contracts 1.9.0: the move needs Accounts' email
A church moved sign-in to Accounts without email set up there: codes and password links couldn't be sent, sign-in failed with a 500, nobody could get in. - contracts 1.9.0: messaging.status/test/set (SMTP, WAWP; secrets sealed); people.ensure answers emailSent. - Accounts 1.2.0: SendError instead of a 500; WhatsApp codes fall back to email; forgot password says email isn't set up; setup only offers methods that work; messaging.* (test, save only what worked); test WhatsApp in admin; WAWP from .env. - Events 3.1.0: Settings -> Sign-in shows what Accounts can send and copies this site's SMTP/WAWP into it (secrets stay on the server), test then save; Move disabled and refused (EMAIL_NOT_READY) without email. Tests: Accounts 54, contracts 218, Events 774, test:accounts 16 (also on Postgres). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -11,6 +11,7 @@ import { hashToken, randomCode, safeEqual } from '../lib/crypto.js';
|
||||
import { loginEvent } from '../lib/audit.js';
|
||||
import { queueCall } from '../links/deliveries.js';
|
||||
import { currentNoticeVersion } from '../privacy/notice.js';
|
||||
import { SendError } from '../lib/messages.js';
|
||||
|
||||
export const MAX_FAILED_SIGN_INS = 10;
|
||||
export const LOCK_MINUTES = 15;
|
||||
@@ -100,18 +101,33 @@ export function maskedTarget(a: Account, method: 'email' | 'whatsapp'): string {
|
||||
return `${user!.slice(0, 1)}***@${domain}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a code. 1.2.0: a WhatsApp code that can't go is sent by email instead (as Cross Events), and
|
||||
* when nothing can send it the person is told so (`SendError`, shown on the page) instead of the
|
||||
* sign-in failing.
|
||||
*/
|
||||
export async function sendCode(ctx: Ctx, a: Account, method: 'email' | 'whatsapp', purpose: 'sign_in' | 'verify_email' | 'setup'): Promise<{ codeHash: string; sentTo: string }> {
|
||||
const code = randomCode();
|
||||
const churchName = (await ctx.settings.json<{ name?: string }>('church_profile', {})).name || 'your church';
|
||||
const what = purpose === 'verify_email' ? 'confirm your email address' : 'sign in';
|
||||
const text = `Your code to ${what} at ${churchName} is ${code}. It works for ${CODE_MINUTES} minutes. If you didn't ask for it, you can ignore this message.`;
|
||||
if (method === 'whatsapp') {
|
||||
if (!a.phone) throw new Error('There\'s no phone number on this account.');
|
||||
await ctx.messenger.whatsapp({ to: a.phone, text });
|
||||
} else {
|
||||
await ctx.messenger.email({ to: a.email, subject: `Your code: ${code}`, text });
|
||||
if (method === 'whatsapp' && a.phone) {
|
||||
try {
|
||||
await ctx.messenger.whatsapp({ to: a.phone, text });
|
||||
return { codeHash: hashToken(code), sentTo: maskedTarget(a, 'whatsapp') };
|
||||
} catch (e) {
|
||||
// Setting WhatsApp up has to prove WhatsApp works, so no email instead then.
|
||||
if (purpose !== 'sign_in') throw new SendError('We couldn\'t send a code by WhatsApp. Choose another way to get your codes.', 'CODE_NOT_SENT');
|
||||
console.warn('[codes] WhatsApp failed, trying email:', (e as Error).message);
|
||||
}
|
||||
}
|
||||
return { codeHash: hashToken(code), sentTo: maskedTarget(a, method) };
|
||||
try {
|
||||
await ctx.messenger.email({ to: a.email, subject: `Your code: ${code}`, text });
|
||||
} catch (e) {
|
||||
console.error('[codes] could not send a code:', (e as Error).message);
|
||||
throw new SendError(`We couldn't send your code: ${churchName}'s email isn't working right now. Please let the church office know, and try again later.`, 'CODE_NOT_SENT');
|
||||
}
|
||||
return { codeHash: hashToken(code), sentTo: maskedTarget(a, 'email') };
|
||||
}
|
||||
|
||||
export const codeMatches = (code: unknown, hash: string | null | undefined) =>
|
||||
|
||||
@@ -196,7 +196,24 @@ export function adminRouter(ctx: Ctx, provider: Provider) {
|
||||
r.post('/settings/test-email', limit(5), handle(async (req, res) => {
|
||||
const me = await admin(req, res);
|
||||
const a = await ctx.db.account.findUniqueOrThrow({ where: { id: me.id } });
|
||||
await ctx.messenger.email({ to: a.email, subject: 'Test email from Accounts', text: 'Email from Accounts works.' });
|
||||
try {
|
||||
await ctx.messenger.email({ to: a.email, subject: 'Test email from Accounts', text: 'Email from Accounts works.' });
|
||||
} catch (e) {
|
||||
throw new ApiError(502, 'NOT_SENT', `The test email couldn't be sent: ${(e as Error).message}`);
|
||||
}
|
||||
return { sent: true };
|
||||
}));
|
||||
|
||||
// 1.2.0: as the test email, for WhatsApp (WAWP), to the admin's own phone.
|
||||
r.post('/settings/test-whatsapp', limit(5), handle(async (req, res) => {
|
||||
const me = await admin(req, res);
|
||||
const a = await ctx.db.account.findUniqueOrThrow({ where: { id: me.id } });
|
||||
if (!a.phone) throw new ApiError(400, 'NO_PHONE', 'Add your mobile number on your account page first.');
|
||||
try {
|
||||
await ctx.messenger.whatsapp({ to: a.phone, text: 'WhatsApp from Accounts works.' });
|
||||
} catch (e) {
|
||||
throw new ApiError(502, 'NOT_SENT', `The test message couldn't be sent: ${(e as Error).message}`);
|
||||
}
|
||||
return { sent: true };
|
||||
}));
|
||||
|
||||
|
||||
@@ -99,19 +99,23 @@ export async function describe(ctx: Ctx, details: Details, pending: PendingSignI
|
||||
};
|
||||
if (stage === 'password' || stage === 'done') return base;
|
||||
const a = await account(ctx, pending);
|
||||
let sentNow: string | null = null;
|
||||
if ((stage === 'verify_email' || (stage === 'two_factor' && a.twoFactorMethod !== 'totp')) && !pending.codeSentAt) {
|
||||
const method = stage === 'verify_email' ? 'email' : (a.twoFactorMethod as 'email' | 'whatsapp');
|
||||
const sent = await sendCode(ctx, a, method, stage === 'verify_email' ? 'verify_email' : 'sign_in');
|
||||
await save(ctx, pending, { codeHash: sent.codeHash, codeSentAt: ctx.now(), attempts: 0 });
|
||||
sentNow = sent.sentTo;
|
||||
}
|
||||
const extra: Record<string, unknown> = { name: a.name, email: a.email };
|
||||
if (stage === 'verify_email') extra.sentTo = maskedTarget(a, 'email');
|
||||
if (stage === 'two_factor') {
|
||||
extra.method = a.twoFactorMethod;
|
||||
if (a.twoFactorMethod !== 'totp') extra.sentTo = maskedTarget(a, a.twoFactorMethod as 'email' | 'whatsapp');
|
||||
// Where it actually went (a WhatsApp code that couldn't go was sent by email).
|
||||
if (a.twoFactorMethod !== 'totp') extra.sentTo = sentNow ?? maskedTarget(a, a.twoFactorMethod as 'email' | 'whatsapp');
|
||||
}
|
||||
if (stage === 'setup_two_factor') {
|
||||
extra.methods = ['totp', 'email', ...((await ctx.messenger.whatsappReady()) && a.phone ? ['whatsapp'] : [])];
|
||||
// Only the ways that can deliver a code now (1.2.0): an app always works.
|
||||
extra.methods = ['totp', ...((await ctx.messenger.emailReady()) ? ['email'] : []), ...((await ctx.messenger.whatsappReady()) && a.phone ? ['whatsapp'] : [])];
|
||||
extra.why = a.role === 'admin' ? 'admin' : 'product';
|
||||
}
|
||||
if (stage === 'notice') {
|
||||
|
||||
@@ -88,6 +88,8 @@ export function interactionRouter(ctx: Ctx, provider: Provider) {
|
||||
// ─── Forgot / reset password ───────────────────────────────────────────────
|
||||
|
||||
r.post('/password/forgot', limit(5), handle(async (req) => {
|
||||
// 1.2.0: without email nobody gets a link; say so (the same answer whoever asks).
|
||||
if (!(await ctx.messenger.emailReady())) throw new ApiError(503, 'EMAIL_NOT_READY', 'Password reset links can\'t be sent right now: the church\'s email isn\'t set up. Please let the church office know.');
|
||||
const email = normaliseEmail(req.body?.email);
|
||||
const a = email ? await ctx.db.account.findUnique({ where: { email } }) : null;
|
||||
// The same answer either way, so nobody can find out who has an account (Events 1.51.17).
|
||||
|
||||
@@ -20,6 +20,8 @@ export type Config = {
|
||||
hubAdminEmail: string | null;
|
||||
timezone: string;
|
||||
smtp: { host: string; port: number; user: string; pass: string; from: string; secure: boolean } | null;
|
||||
/** 1.2.0: WAWP from the .env when the database has none (as Cross Events). */
|
||||
wawp: { accessToken: string; instanceId: string } | null;
|
||||
/** Local testing only: linked products on http or private addresses. */
|
||||
allowPrivateLinks: boolean;
|
||||
jobsEnabled: boolean;
|
||||
@@ -67,6 +69,7 @@ export function loadConfig(env: Record<string, string | undefined> = process.env
|
||||
smtp: env.SMTP_HOST
|
||||
? { host: env.SMTP_HOST, port: Number(env.SMTP_PORT || 587), user: env.SMTP_USER || '', pass: env.SMTP_PASS || '', from: env.SMTP_FROM || env.SMTP_USER || '', secure: bool(env.SMTP_SECURE, Number(env.SMTP_PORT) === 465) }
|
||||
: null,
|
||||
wawp: env.WAWP_ACCESS_TOKEN && env.WAWP_INSTANCE_ID ? { accessToken: env.WAWP_ACCESS_TOKEN, instanceId: env.WAWP_INSTANCE_ID } : null,
|
||||
allowPrivateLinks: bool(env.LINKS_ALLOW_PRIVATE, false),
|
||||
jobsEnabled: bool(env.JOBS_ENABLED, true),
|
||||
};
|
||||
|
||||
@@ -8,11 +8,49 @@ import type { Ctx } from '../context.js';
|
||||
export type Email = { to: string; subject: string; text: string };
|
||||
export type WhatsApp = { to: string; text: string };
|
||||
|
||||
/** SMTP settings to try before saving them (1.2.0), as kept in `smtp_*`. */
|
||||
export type SmtpTry = { host: string; port: number; secure: boolean; user: string; pass: string; from: string };
|
||||
/** WAWP settings to try before saving them (1.2.0). */
|
||||
export type WawpTry = { accessToken: string; instanceId: string };
|
||||
|
||||
export interface Messenger {
|
||||
email(msg: Email): Promise<void>;
|
||||
whatsapp(msg: WhatsApp): Promise<void>;
|
||||
/** Whether email is set up (sign-in codes, password links and new accounts need it). */
|
||||
emailReady(): Promise<boolean>;
|
||||
/** Whether WhatsApp is set up, so it's offered as a 2FA method. */
|
||||
whatsappReady(): Promise<boolean>;
|
||||
/** Sends one email with settings that aren't saved (a test before saving them). Throws why it failed. */
|
||||
emailWith(settings: SmtpTry, msg: Email): Promise<void>;
|
||||
/** Sends one WhatsApp message with settings that aren't saved. Throws why it failed. */
|
||||
whatsappWith(settings: WawpTry, msg: WhatsApp): Promise<void>;
|
||||
}
|
||||
|
||||
/** Thrown when a message can't be sent: the sign-in pages show it instead of failing. */
|
||||
export class SendError extends Error {
|
||||
status = 503;
|
||||
constructor(message: string, public code = 'NOT_SENT') {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
|
||||
function transportFor(s: SmtpTry) {
|
||||
return nodemailer.createTransport({
|
||||
host: s.host, port: s.port, secure: s.secure, auth: s.user ? { user: s.user, pass: s.pass } : undefined,
|
||||
connectionTimeout: 15000, greetingTimeout: 15000, socketTimeout: 20000,
|
||||
});
|
||||
}
|
||||
|
||||
async function wawpSend(s: WawpTry, msg: WhatsApp) {
|
||||
const number = waNumber(msg.to);
|
||||
if (!number) throw new Error('That isn\'t a WhatsApp number.');
|
||||
const res = await fetch('https://api.wawp.net/v2/send/text', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ access_token: s.accessToken, instance_id: s.instanceId, chatId: `${number}@c.us`, message: msg.text }),
|
||||
signal: AbortSignal.timeout(15000),
|
||||
});
|
||||
if (!res.ok) throw new Error(`WhatsApp couldn't send the message (${res.status}).`);
|
||||
}
|
||||
|
||||
/** 0821234567 / +27 82 123 4567 → 27821234567 (South African mobiles; others as given, digits only). */
|
||||
@@ -52,23 +90,33 @@ export class LiveMessenger implements Messenger {
|
||||
await smtp.transport.sendMail({ from: church ? `"${church.replace(/"/g, '')}" <${smtp.from}>` : smtp.from, to: msg.to, subject: msg.subject, text: msg.text });
|
||||
}
|
||||
|
||||
async emailReady(): Promise<boolean> {
|
||||
return !!(await this.smtp());
|
||||
}
|
||||
|
||||
private async wawp(): Promise<WawpTry | null> {
|
||||
const accessToken = (await this.ctx.settings.get('wawp_access_token')) || this.ctx.config.wawp?.accessToken;
|
||||
const instanceId = (await this.ctx.settings.get('wawp_instance_id')) || this.ctx.config.wawp?.instanceId;
|
||||
return accessToken && instanceId ? { accessToken, instanceId } : null;
|
||||
}
|
||||
|
||||
async whatsappReady(): Promise<boolean> {
|
||||
return !!((await this.ctx.settings.get('wawp_access_token')) && (await this.ctx.settings.get('wawp_instance_id')));
|
||||
return !!(await this.wawp());
|
||||
}
|
||||
|
||||
async whatsapp(msg: WhatsApp): Promise<void> {
|
||||
const token = await this.ctx.settings.get('wawp_access_token');
|
||||
const instance = await this.ctx.settings.get('wawp_instance_id');
|
||||
const number = waNumber(msg.to);
|
||||
if (!token || !instance) throw new Error('WhatsApp isn\'t set up.');
|
||||
if (!number) throw new Error('That isn\'t a WhatsApp number.');
|
||||
const res = await fetch('https://api.wawp.net/v2/send/text', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ access_token: token, instance_id: instance, chatId: `${number}@c.us`, message: msg.text }),
|
||||
signal: AbortSignal.timeout(15000),
|
||||
});
|
||||
if (!res.ok) throw new Error(`WhatsApp couldn't send the message (${res.status}).`);
|
||||
const s = await this.wawp();
|
||||
if (!s) throw new Error('WhatsApp isn\'t set up.');
|
||||
await wawpSend(s, msg);
|
||||
}
|
||||
|
||||
async emailWith(settings: SmtpTry, msg: Email): Promise<void> {
|
||||
const church = (await this.ctx.settings.json<{ name?: string }>('church_profile', {})).name;
|
||||
await transportFor(settings).sendMail({ from: church ? `"${church.replace(/"/g, '')}" <${settings.from}>` : settings.from, to: msg.to, subject: msg.subject, text: msg.text });
|
||||
}
|
||||
|
||||
async whatsappWith(settings: WawpTry, msg: WhatsApp): Promise<void> {
|
||||
await wawpSend(settings, msg);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,9 +124,30 @@ export class MemoryMessenger implements Messenger {
|
||||
emails: Email[] = [];
|
||||
whatsapps: WhatsApp[] = [];
|
||||
whatsappOn = false;
|
||||
async email(msg: Email) { this.emails.push(msg); }
|
||||
async whatsapp(msg: WhatsApp) { this.whatsapps.push(msg); }
|
||||
/** Tests: false makes email fail as an unset SMTP does in production. */
|
||||
emailOn = true;
|
||||
/** Tests: settings tried with emailWith / whatsappWith, and a host that fails. */
|
||||
tried: { kind: 'email' | 'whatsapp'; settings: SmtpTry | WawpTry; to: string }[] = [];
|
||||
failHost: string | null = null;
|
||||
async email(msg: Email) {
|
||||
if (!this.emailOn) throw new Error('Email isn\'t set up (Admin → Email and WhatsApp).');
|
||||
this.emails.push(msg);
|
||||
}
|
||||
async whatsapp(msg: WhatsApp) {
|
||||
if (!this.whatsappOn) throw new Error('WhatsApp isn\'t set up.');
|
||||
this.whatsapps.push(msg);
|
||||
}
|
||||
async emailReady() { return this.emailOn; }
|
||||
async whatsappReady() { return this.whatsappOn; }
|
||||
async emailWith(settings: SmtpTry, msg: Email) {
|
||||
this.tried.push({ kind: 'email', settings, to: msg.to });
|
||||
if (settings.host === this.failHost) throw new Error(`connect ECONNREFUSED ${settings.host}:${settings.port}`);
|
||||
this.emails.push(msg);
|
||||
}
|
||||
async whatsappWith(settings: WawpTry, msg: WhatsApp) {
|
||||
this.tried.push({ kind: 'whatsapp', settings, to: msg.to });
|
||||
this.whatsapps.push(msg);
|
||||
}
|
||||
/** The last 6-digit code sent to `to` (tests). */
|
||||
lastCode(to: string): string | null {
|
||||
const all = [...this.emails.filter((e) => e.to === to).map((e) => e.text), ...this.whatsapps.filter((w) => w.to === to).map((w) => w.text)];
|
||||
|
||||
@@ -227,14 +227,22 @@ async function handle(ctx: Ctx, provider: Provider, link: ProductLink, secret: s
|
||||
const returnUrl = new URL(r.returnUrl).origin === new URL(link.url).origin ? r.returnUrl : link.url;
|
||||
await ctx.db.emailToken.create({ data: { accountId: a.id, purpose: 'reset_password', tokenHash: hashToken(token), returnUrl, expiresAt: new Date(ctx.now().getTime() + SET_PASSWORD_DAYS * 86400e3) } });
|
||||
const churchName = (await ctx.settings.json<{ name?: string }>('church_profile', {})).name || 'your church';
|
||||
await ctx.messenger.email({
|
||||
to: email,
|
||||
subject: `Your account at ${churchName}`,
|
||||
text: `Hello ${r.name},\n\n${churchName} has made you an account. Choose your password here (the link works for ${SET_PASSWORD_DAYS} days):\n${ctx.config.publicUrl}/reset?token=${token}\n\nIf you weren't expecting this, you can ignore this email.`,
|
||||
});
|
||||
// 1.2.0: the account stands even when the email can't go (they can use "Forgot your password?"
|
||||
// once email works); the product is told.
|
||||
let emailSent = true;
|
||||
try {
|
||||
await ctx.messenger.email({
|
||||
to: email,
|
||||
subject: `Your account at ${churchName}`,
|
||||
text: `Hello ${r.name},\n\n${churchName} has made you an account. Choose your password here (the link works for ${SET_PASSWORD_DAYS} days):\n${ctx.config.publicUrl}/reset?token=${token}\n\nIf you weren't expecting this, you can ignore this email.`,
|
||||
});
|
||||
} catch (e) {
|
||||
emailSent = false;
|
||||
console.warn('[people.ensure] the "choose your password" email could not be sent:', (e as Error).message);
|
||||
}
|
||||
await loginEvent(ctx, a.id, 'account_created', req, { clientId: link.installId, detail: { by: 'product', product: link.product } });
|
||||
await logRequest(ctx, link, r, 'person_created_by_product', a.id, req);
|
||||
return reply({ sub: a.id, created: true });
|
||||
await logRequest(ctx, link, r, 'person_created_by_product', a.id, req, { emailSent });
|
||||
return reply({ sub: a.id, created: true, emailSent });
|
||||
}
|
||||
case 'people.update': {
|
||||
const a = await knownAccount(ctx, link, r.sub);
|
||||
@@ -282,6 +290,48 @@ async function handle(ctx: Ctx, provider: Provider, link: ProductLink, secret: s
|
||||
await logRequest(ctx, link, r, r.active ? 'account_reactivated_by_product' : 'account_deactivated_by_product', a.id, req);
|
||||
return reply({ ok: true as const });
|
||||
}
|
||||
case 'messaging.status':
|
||||
return reply(await messagingStatus(ctx));
|
||||
case 'messaging.test':
|
||||
case 'messaging.set': {
|
||||
const save = r.type === 'messaging.set';
|
||||
const church = (await ctx.settings.json<{ name?: string }>('church_profile', {})).name || 'your church';
|
||||
let email: { ok: boolean; error: string | null; saved: boolean } | null = null;
|
||||
let whatsapp: { ok: boolean; error: string | null; saved: boolean } | null = null;
|
||||
if (r.email) {
|
||||
const s = r.email.settings;
|
||||
const pass = s.pass === null ? ((await ctx.settings.get('smtp_pass')) ?? '') : opened(secret, s.pass, 'SMTP password');
|
||||
const tryWith = { host: s.host, port: s.port, secure: s.secure, user: s.user, pass: pass ?? '', from: s.from };
|
||||
try {
|
||||
await ctx.messenger.emailWith(tryWith, { to: r.email.to, subject: `Test email from ${church}'s sign-in`, text: `This is a test from ${church}'s sign-in (Accounts), sent from ${link.product === 'events' ? 'Cross Events' : link.product}. Email works: sign-in codes and password links can be sent.` });
|
||||
email = { ok: true, error: null, saved: false };
|
||||
if (save) {
|
||||
await ctx.settings.setMany({ smtp_host: s.host, smtp_port: String(s.port), smtp_secure: String(s.secure), smtp_user: s.user, smtp_from: s.from, ...(s.pass === null ? {} : { smtp_pass: pass }) });
|
||||
email.saved = true;
|
||||
}
|
||||
} catch (e) {
|
||||
email = { ok: false, error: String((e as Error).message || e).slice(0, 500), saved: false };
|
||||
}
|
||||
}
|
||||
if (r.whatsapp) {
|
||||
const s = r.whatsapp.settings;
|
||||
const token = s.accessToken === null ? ((await ctx.settings.get('wawp_access_token')) ?? '') : opened(secret, s.accessToken, 'WAWP access token');
|
||||
try {
|
||||
if (!token) throw new Error('Give the WAWP access token.');
|
||||
await ctx.messenger.whatsappWith({ accessToken: token, instanceId: s.instanceId }, { to: r.whatsapp.to, text: `This is a test from ${church}'s sign-in. WhatsApp works: sign-in codes can be sent.` });
|
||||
whatsapp = { ok: true, error: null, saved: false };
|
||||
if (save) {
|
||||
await ctx.settings.setMany({ wawp_instance_id: s.instanceId, ...(s.accessToken === null ? {} : { wawp_access_token: token }) });
|
||||
whatsapp.saved = true;
|
||||
}
|
||||
} catch (e) {
|
||||
whatsapp = { ok: false, error: String((e as Error).message || e).slice(0, 500), saved: false };
|
||||
}
|
||||
}
|
||||
await logRequest(ctx, link, r, save ? 'messaging_set_by_product' : 'messaging_tested_by_product', null, req, { email: email && { ok: email.ok, saved: email.saved }, whatsapp: whatsapp && { ok: whatsapp.ok, saved: whatsapp.saved } });
|
||||
const status = await messagingStatus(ctx);
|
||||
return reply({ email, whatsapp, status: { email: status.email, whatsapp: status.whatsapp } });
|
||||
}
|
||||
case 'people.newsOff': {
|
||||
const a = await knownAccount(ctx, link, r.sub);
|
||||
const off = r.channel === 'all' ? { email: false, whatsapp: false } : { [r.channel]: false };
|
||||
@@ -328,6 +378,15 @@ export function requestsRouter(ctx: Ctx, provider: Provider) {
|
||||
return r;
|
||||
}
|
||||
|
||||
/** What can be sent now (no secrets), for a product's sign-in settings page. */
|
||||
async function messagingStatus(ctx: Ctx) {
|
||||
const emailReady = await ctx.messenger.emailReady();
|
||||
return {
|
||||
email: { ready: emailReady, host: emailReady ? ((await ctx.settings.get('smtp_host')) || ctx.config.smtp?.host || null) : null, from: emailReady ? ((await ctx.settings.get('smtp_from')) || ctx.config.smtp?.from || null) : null },
|
||||
whatsapp: { ready: await ctx.messenger.whatsappReady(), instanceId: (await ctx.settings.get('wawp_instance_id')) || ctx.config.wawp?.instanceId || null },
|
||||
};
|
||||
}
|
||||
|
||||
/** Old remembered requests (the `cleanup` job). */
|
||||
export async function forgetOldRequests(ctx: Ctx) {
|
||||
return ctx.db.productRequest.deleteMany({ where: { createdAt: { lt: new Date(ctx.now().getTime() - KEEP_REQUESTS_DAYS * 86400e3) } } });
|
||||
|
||||
Reference in New Issue
Block a user