Merge pull request 'feat(api): show the verification code in the SES mailbox' (#10) from feat/emails-page into main
CI / checks (push) Has been cancelled

Reviewed-on: #10
This commit was merged in pull request #10.
This commit is contained in:
2026-10-24 05:29:58 +00:00
3 changed files with 22 additions and 0 deletions
@@ -46,6 +46,19 @@ describe('AwsSesAdapter', () => {
})])
})
test('picks out the code from verification emails', async () => {
const adapter = new AwsSesAdapter('http://floci.test', async () => jsonResponse({
messages: [
{Id: 'cognito', Subject: 'Your verification code', Body: {text_part: 'Your verification code is 869472.'}},
{Id: 'html', Subject: 'Reset', Body: {html_part: '<p>Your confirmation code is: <b>4410</b></p>'}},
{Id: 'plain', Subject: 'Invoice', Body: {text_part: 'Order 123456 shipped.'}},
],
}))
const codes = (await adapter.list()).map((resource) => resource.metadata.code)
expect(codes).toEqual(['869472', '4410', null])
})
test('filters messages by subject, sender, and recipients', async () => {
const adapter = new AwsSesAdapter('http://floci.test', async () => jsonResponse({
messages: [
@@ -125,10 +125,18 @@ function messageToResource(message: FlociSesMessage): CloudResource {
htmlBody: message.Body?.html_part ?? null,
rawData: message.RawData ?? null,
messageType: raw ? 'raw' : 'simple',
code: findCode(message.Body?.text_part ?? message.Body?.html_part),
},
}
}
// Matches the wording of Cognito's default and most custom messages: "Your verification code is 123456."
const CODE_PATTERN = /\bcode\s+is:?\s*(?:<[^>]+>\s*)*(\d{4,8})\b/i
function findCode(body: string | null | undefined): string | null {
return body?.match(CODE_PATTERN)?.[1] ?? null
}
function filterBySearch(resources: CloudResource[], search?: string): CloudResource[] {
const normalized = search?.trim().toLowerCase()
if (!normalized) return resources
@@ -4,6 +4,7 @@ const emailColumns: TableColumnSchema[] = [
{name: 'name', label: 'Subject'},
{name: 'source', label: 'From', path: 'metadata.source', format: 'code'},
{name: 'to', label: 'To', path: 'metadata.toAddresses', format: 'list'},
{name: 'code', label: 'Code', path: 'metadata.code', format: 'code'},
{name: 'messageType', label: 'Type', path: 'metadata.messageType', format: 'badge'},
{name: 'createdAt', label: 'Captured At', format: 'datetime'},
]