feat(iios): EmailAdapter (email-native normalize + threading) in adapter-sdk

Adds a canonical EmailInboundPayload + EmailAdapter implementing the
ChannelAdapter contract: HMAC signature verify + normalize with email-native
threading (whole reply chain → one IIOS thread via references/inReplyTo root),
messageId as providerEventId for dedup, html→text fallback, Re:/Fwd: stripping.
Plus emailInboundFixture/emailReplyFixture and unit tests.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-07-03 20:25:00 +05:30
parent 427396653f
commit ae50f56404
4 changed files with 139 additions and 2 deletions
+26 -1
View File
@@ -1,7 +1,8 @@
import { hmacSign } from './hmac';
import type { WebhookPayload } from './webhook-adapter';
import type { EmailInboundPayload } from './email-adapter';
/** Email-shaped provider payload (as the adapter's normalize input). */
/** Email-shaped WebhookPayload (legacy generic-webhook fixture). */
export const emailFixture: WebhookPayload = {
eventId: 'email-1',
from: 'someone@example.com',
@@ -11,6 +12,30 @@ export const emailFixture: WebhookPayload = {
text: 'Hello, I have a question.',
};
/** A first inbound email (starts a thread) for the EmailAdapter. */
export const emailInboundFixture: EmailInboundPayload = {
messageId: '<m1@example.com>',
from: 'buyer@example.com',
fromName: 'Buyer',
to: ['support@tower.example'],
subject: 'Need help with my order',
text: 'Hi, my order has not arrived yet.',
occurredAt: '2026-07-03T10:00:00.000Z',
};
/** A reply to `emailInboundFixture` — must land on the SAME email thread. */
export const emailReplyFixture: EmailInboundPayload = {
messageId: '<m2@example.com>',
from: 'buyer@example.com',
fromName: 'Buyer',
to: ['support@tower.example'],
subject: 'Re: Need help with my order',
text: 'Any update on this?',
inReplyTo: '<m1@example.com>',
references: ['<m1@example.com>'],
occurredAt: '2026-07-03T11:00:00.000Z',
};
/** WhatsApp-shaped provider payload. */
export const whatsappFixture: WebhookPayload = {
eventId: 'wa-1',