mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-30 08:30:05 +00:00
feat(mail-ingest): the transport settings in the admin form, each overridable from the environment
The IMAP box, the webhook secret and the address template join the admin settings form (masked, encrypted, held by the operator on a managed install), and MAIL_INGEST_* variables override them through the mailIngestConfig token. The audit row masks every masked key, and key rotation covers the new secrets.
This commit is contained in:
@@ -8,6 +8,7 @@ import {
|
||||
import {
|
||||
mailIngestAddressSchema,
|
||||
mailIngestAdminStatusResponseSchema,
|
||||
mailIngestAdminTestResponseSchema,
|
||||
mailIngestApplyRequestSchema,
|
||||
mailIngestCandidateSchema,
|
||||
mailIngestFileRequestSchema,
|
||||
@@ -137,6 +138,13 @@ describe('mail-ingest rows', () => {
|
||||
expect(mailIngestAdminStatusResponseSchema.safeParse(status).success).toBe(true);
|
||||
expect(mailIngestInboundResponseSchema.safeParse({ accepted: true, duplicate: false }).success).toBe(true);
|
||||
});
|
||||
|
||||
it('MAILC-016: the connection test names its transport and what failed', () => {
|
||||
expect(mailIngestAdminTestResponseSchema.safeParse({ transport: 'imap', ok: true, error: null }).success).toBe(true);
|
||||
const failed = { transport: 'webhook', ok: false, error: 'No webhook secret is set' };
|
||||
expect(mailIngestAdminTestResponseSchema.safeParse(failed).success).toBe(true);
|
||||
expect(mailIngestAdminTestResponseSchema.safeParse({ transport: 'smtp', ok: true, error: null }).success).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('mail-ingest requests', () => {
|
||||
@@ -152,6 +160,7 @@ describe('mail-ingest requests', () => {
|
||||
expect(mailIngestApplyRequestSchema.safeParse({ trip_id: 3 }).success).toBe(true);
|
||||
expect(mailIngestApplyRequestSchema.safeParse({ trip_id: 0 }).success).toBe(false);
|
||||
expect(mailIngestMoveRequestSchema.safeParse({}).success).toBe(false);
|
||||
expect(mailIngestMoveRequestSchema.safeParse({ trip_id: 3, confirm: true }).success).toBe(true);
|
||||
expect(mailIngestFileRequestSchema.safeParse({ trip_id: 3, reservation_id: 4 }).success).toBe(false);
|
||||
});
|
||||
|
||||
|
||||
@@ -229,8 +229,13 @@ export type MailIngestMessagePreviewResponse = z.infer<typeof mailIngestMessageP
|
||||
export const mailIngestApplyRequestSchema = z.strictObject({ trip_id: idSchema.optional() });
|
||||
export type MailIngestApplyRequest = z.infer<typeof mailIngestApplyRequestSchema>;
|
||||
|
||||
/** POST /api/mail-ingest/candidates/:id/move: the added booking into another trip. */
|
||||
export const mailIngestMoveRequestSchema = z.strictObject({ trip_id: idSchema });
|
||||
/**
|
||||
* POST /api/mail-ingest/candidates/:id/move: the added booking into another
|
||||
* trip, written there anew. One whose cost has moved balances, or that was
|
||||
* edited since, moves only with `confirm`, as an undo does (409
|
||||
* {@link mailIngestUndoConflictSchema}).
|
||||
*/
|
||||
export const mailIngestMoveRequestSchema = z.strictObject({ trip_id: idSchema, confirm: z.boolean().optional() });
|
||||
export type MailIngestMoveRequest = z.infer<typeof mailIngestMoveRequestSchema>;
|
||||
|
||||
/** POST /api/mail-ingest/candidates/:id/file: the mail's attachments, or its text, as documents of a trip. */
|
||||
@@ -331,3 +336,19 @@ export const mailIngestAdminStatusResponseSchema = z.object({
|
||||
backlog: z.array(countSchema),
|
||||
});
|
||||
export type MailIngestAdminStatusResponse = z.infer<typeof mailIngestAdminStatusResponseSchema>;
|
||||
|
||||
/**
|
||||
* POST /api/admin/mail-ingest/test: whether the configured transport can
|
||||
* reach its mail now (the IMAP box opens, the webhook has its secret, the
|
||||
* TREK Cloud relay is attached). `error` says what failed, never a password.
|
||||
*/
|
||||
export const mailIngestAdminTestResponseSchema = z.object({
|
||||
transport: mailIngestTransportSettingSchema,
|
||||
ok: z.boolean(),
|
||||
error: z.string().nullable(),
|
||||
});
|
||||
export type MailIngestAdminTestResponse = z.infer<typeof mailIngestAdminTestResponseSchema>;
|
||||
|
||||
/** The IMAP box's encryption: TLS from the first byte (port 993), or STARTTLS on a plain port (143). */
|
||||
export const mailIngestImapTlsSchema = z.enum(['tls', 'starttls']);
|
||||
export type MailIngestImapTls = z.infer<typeof mailIngestImapTlsSchema>;
|
||||
|
||||
Reference in New Issue
Block a user