Compare commits

..

2 Commits

Author SHA1 Message Date
Zakaria d457c08b12 feat(api): show the verification code in the SES mailbox
CI / checks (pull_request) Failing after 12m24s
2026-10-24 01:23:56 -04:00
Zakaria 4bc8da6ee1 Merge pull request 'feat(api): Cognito user actions, groups and test sign-in' (#9) from feat/cognito-round-2 into main
CI / checks (push) Failing after 12m34s
Reviewed-on: #9
2026-10-23 22:56:19 +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'},
]