@open-mercato/channel-resend 0.9.1-develop.7574.1.837288eec1 → 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -16,15 +16,19 @@ function resolveResendErrorMessage(result) {
16
16
  }
17
17
  return null;
18
18
  }
19
+ function headerOrUndefined(value) {
20
+ const text = stringOrUndefined(value);
21
+ return text === void 0 ? void 0 : sanitizeHeaderValue(text);
22
+ }
19
23
  function attachmentsFromMeta(value) {
20
24
  if (!Array.isArray(value)) return void 0;
21
25
  const attachments = value.flatMap((item) => {
22
26
  if (!item || typeof item !== "object") return [];
23
27
  const record = item;
24
- const filename = stringOrUndefined(record.filename);
28
+ const filename = headerOrUndefined(record.filename);
25
29
  const content = stringOrUndefined(record.content);
26
30
  if (!filename || !content) return [];
27
- const contentType = stringOrUndefined(record.contentType);
31
+ const contentType = headerOrUndefined(record.contentType);
28
32
  return [{ filename, content, ...contentType ? { contentType } : {} }];
29
33
  });
30
34
  return attachments.length ? attachments : void 0;
@@ -42,17 +46,18 @@ class ResendChannelAdapter {
42
46
  if (to.length === 0) {
43
47
  return { externalMessageId: "", status: "failed", error: "[internal] Email send requires at least one recipient" };
44
48
  }
45
- const subject = stringOrUndefined(meta.subject);
49
+ const subject = headerOrUndefined(meta.subject);
46
50
  if (!subject) {
47
51
  return { externalMessageId: "", status: "failed", error: "[internal] Email send requires a subject" };
48
52
  }
49
53
  const client = new Resend(credentials.apiKey);
50
54
  const resendAttachments = attachmentsFromMeta(meta.attachments);
55
+ const replyTo = headerOrUndefined(meta.replyTo);
51
56
  const basePayload = {
52
- from: stringOrUndefined(meta.from) ?? credentials.fromAddress,
57
+ from: headerOrUndefined(meta.from) ?? credentials.fromAddress,
53
58
  to,
54
59
  subject,
55
- ...stringOrUndefined(meta.replyTo) ? { replyTo: stringOrUndefined(meta.replyTo) } : {},
60
+ ...replyTo ? { replyTo } : {},
56
61
  ...resendAttachments?.length ? { attachments: resendAttachments } : {}
57
62
  };
58
63
  const payload = input.content.html ? { ...basePayload, html: input.content.html, ...input.content.text ? { text: input.content.text } : {} } : { ...basePayload, text: input.content.text ?? "" };
@@ -80,7 +85,7 @@ class ResendChannelAdapter {
80
85
  async convertOutbound(input) {
81
86
  const meta = input.channelMetadata ?? {};
82
87
  const to = toAddressList(meta.to).map(sanitizeHeaderValue);
83
- const subject = stringOrUndefined(meta.subject);
88
+ const subject = headerOrUndefined(meta.subject);
84
89
  const html = input.bodyFormat === "html" ? input.body : void 0;
85
90
  const text = input.bodyFormat === "html" ? htmlToText(input.body) : input.body;
86
91
  return {
@@ -92,8 +97,8 @@ class ResendChannelAdapter {
92
97
  metadata: {
93
98
  to,
94
99
  subject,
95
- from: stringOrUndefined(meta.from),
96
- replyTo: stringOrUndefined(meta.replyTo),
100
+ from: headerOrUndefined(meta.from),
101
+ replyTo: headerOrUndefined(meta.replyTo),
97
102
  attachments: attachmentsFromMeta(meta.attachments)
98
103
  }
99
104
  };
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../src/modules/channel_resend/lib/adapter.ts"],
4
- "sourcesContent": ["import { Resend } from 'resend'\nimport type {\n ChannelAdapter,\n ChannelNativeContent,\n ConvertOutboundInput,\n GetMessageStatusInput,\n InboundMessage,\n MessageStatus,\n NormalizedInboundMessage,\n SendMessageInput,\n SendMessageResult,\n VerifyWebhookInput,\n} from '@open-mercato/core/modules/communication_channels/lib/adapter'\nimport {\n htmlToText,\n sanitizeHeaderValue,\n stringOrUndefined,\n toAddressList,\n} from '@open-mercato/core/modules/communication_channels/lib/email-mime'\nimport { resendCapabilities } from '../capabilities'\nimport { resendCredentialsSchema } from './credentials'\n\ntype ResendAttachment = {\n filename: string\n content: string\n contentType?: string\n}\n\ntype ResendSendResult = {\n data?: { id?: string | null } | null\n error?: unknown\n}\n\nfunction resolveResendErrorMessage(result: unknown): string | null {\n const value = result as ResendSendResult\n if (typeof value.error === 'string') return value.error\n if (value.error && typeof value.error === 'object' && 'message' in value.error) {\n const message = (value.error as { message?: unknown }).message\n return typeof message === 'string' ? message : null\n }\n return null\n}\n\nfunction attachmentsFromMeta(value: unknown): ResendAttachment[] | undefined {\n if (!Array.isArray(value)) return undefined\n const attachments = value.flatMap((item): ResendAttachment[] => {\n if (!item || typeof item !== 'object') return []\n const record = item as Record<string, unknown>\n const filename = stringOrUndefined(record.filename)\n const content = stringOrUndefined(record.content)\n if (!filename || !content) return []\n const contentType = stringOrUndefined(record.contentType)\n return [{ filename, content, ...(contentType ? { contentType } : {}) }]\n })\n return attachments.length ? attachments : undefined\n}\n\nclass ResendChannelAdapter implements ChannelAdapter {\n readonly providerKey = 'resend'\n readonly channelType = 'email'\n readonly capabilities = resendCapabilities\n\n async sendMessage(input: SendMessageInput): Promise<SendMessageResult> {\n const credentials = resendCredentialsSchema.parse(input.credentials)\n const meta = (input.metadata ?? {}) as Record<string, unknown>\n const to = toAddressList(meta.to).map(sanitizeHeaderValue)\n if (to.length === 0) {\n return { externalMessageId: '', status: 'failed', error: '[internal] Email send requires at least one recipient' }\n }\n const subject = stringOrUndefined(meta.subject)\n if (!subject) {\n return { externalMessageId: '', status: 'failed', error: '[internal] Email send requires a subject' }\n }\n\n const client = new Resend(credentials.apiKey)\n const resendAttachments = attachmentsFromMeta(meta.attachments)\n const basePayload = {\n from: stringOrUndefined(meta.from) ?? credentials.fromAddress,\n to,\n subject,\n ...(stringOrUndefined(meta.replyTo) ? { replyTo: stringOrUndefined(meta.replyTo) } : {}),\n ...(resendAttachments?.length ? { attachments: resendAttachments } : {}),\n }\n const payload: Parameters<typeof client.emails.send>[0] = input.content.html\n ? { ...basePayload, html: input.content.html, ...(input.content.text ? { text: input.content.text } : {}) }\n : { ...basePayload, text: input.content.text ?? '' }\n const result = await client.emails.send(payload)\n const errorMessage = resolveResendErrorMessage(result)\n if (errorMessage) {\n return { externalMessageId: '', status: 'failed', error: `RESEND_SEND_FAILED: ${errorMessage}` }\n }\n const sentId = (result as ResendSendResult).data?.id\n return {\n externalMessageId: sentId || `resend:${Date.now()}`,\n conversationId: input.conversationId,\n status: 'sent',\n }\n }\n\n async verifyWebhook(_input: VerifyWebhookInput): Promise<InboundMessage> {\n return { raw: {}, eventType: 'other', metadata: { reason: 'resend-system-email-outbound-only' } }\n }\n\n async getStatus(_input: GetMessageStatusInput): Promise<MessageStatus> {\n return { status: 'sent' }\n }\n\n async normalizeInbound(_raw: InboundMessage): Promise<NormalizedInboundMessage> {\n throw new Error('[internal] Resend system email adapter is outbound-only')\n }\n\n async convertOutbound(input: ConvertOutboundInput): Promise<ChannelNativeContent> {\n const meta = (input.channelMetadata ?? {}) as Record<string, unknown>\n const to = toAddressList(meta.to).map(sanitizeHeaderValue)\n const subject = stringOrUndefined(meta.subject)\n const html = input.bodyFormat === 'html' ? input.body : undefined\n const text = input.bodyFormat === 'html' ? htmlToText(input.body) : input.body\n return {\n content: {\n text,\n html,\n bodyFormat: input.bodyFormat,\n },\n metadata: {\n to,\n subject,\n from: stringOrUndefined(meta.from),\n replyTo: stringOrUndefined(meta.replyTo),\n attachments: attachmentsFromMeta(meta.attachments),\n },\n }\n }\n}\n\nconst adapter = new ResendChannelAdapter()\n\nexport function getResendChannelAdapter(): ChannelAdapter {\n return adapter\n}\n"],
5
- "mappings": "AAAA,SAAS,cAAc;AAavB;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,0BAA0B;AACnC,SAAS,+BAA+B;AAaxC,SAAS,0BAA0B,QAAgC;AACjE,QAAM,QAAQ;AACd,MAAI,OAAO,MAAM,UAAU,SAAU,QAAO,MAAM;AAClD,MAAI,MAAM,SAAS,OAAO,MAAM,UAAU,YAAY,aAAa,MAAM,OAAO;AAC9E,UAAM,UAAW,MAAM,MAAgC;AACvD,WAAO,OAAO,YAAY,WAAW,UAAU;AAAA,EACjD;AACA,SAAO;AACT;AAEA,SAAS,oBAAoB,OAAgD;AAC3E,MAAI,CAAC,MAAM,QAA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AA,QACA,YAAY,MAAM;AAAA,MACpB;AAAA,MACA,UAAU;AAAA,QACR;AAAA,QACA;AAAA,QACA,MAAM,kBAAkB,KAAK,IAAI;AAAA,QACjC,SAAS,kBAAkB,KAAK,OAAO;AAAA,QACvC,aAAa,oBAAoB,KAAK,WAAW;AAAA,MACnD;AAAA,IACF;AAAA,EACF;AACF;AAEA,MAAM,UAAU,IAAI,qBAAqB;AAElC,SAAS,0BAA0C;AACxD,SAAO;AACT;",
4
+ "sourcesContent": ["import { Resend } from 'resend'\nimport type {\n ChannelAdapter,\n ChannelNativeContent,\n ConvertOutboundInput,\n GetMessageStatusInput,\n InboundMessage,\n MessageStatus,\n NormalizedInboundMessage,\n SendMessageInput,\n SendMessageResult,\n VerifyWebhookInput,\n} from '@open-mercato/core/modules/communication_channels/lib/adapter'\nimport {\n htmlToText,\n sanitizeHeaderValue,\n stringOrUndefined,\n toAddressList,\n} from '@open-mercato/core/modules/communication_channels/lib/email-mime'\nimport { resendCapabilities } from '../capabilities'\nimport { resendCredentialsSchema } from './credentials'\n\ntype ResendAttachment = {\n filename: string\n content: string\n contentType?: string\n}\n\ntype ResendSendResult = {\n data?: { id?: string | null } | null\n error?: unknown\n}\n\nfunction resolveResendErrorMessage(result: unknown): string | null {\n const value = result as ResendSendResult\n if (typeof value.error === 'string') return value.error\n if (value.error && typeof value.error === 'object' && 'message' in value.error) {\n const message = (value.error as { message?: unknown }).message\n return typeof message === 'string' ? message : null\n }\n return null\n}\n\nfunction headerOrUndefined(value: unknown): string | undefined {\n const text = stringOrUndefined(value)\n return text === undefined ? undefined : sanitizeHeaderValue(text)\n}\n\nfunction attachmentsFromMeta(value: unknown): ResendAttachment[] | undefined {\n if (!Array.isArray(value)) return undefined\n const attachments = value.flatMap((item): ResendAttachment[] => {\n if (!item || typeof item !== 'object') return []\n const record = item as Record<string, unknown>\n const filename = headerOrUndefined(record.filename)\n const content = stringOrUndefined(record.content)\n if (!filename || !content) return []\n const contentType = headerOrUndefined(record.contentType)\n return [{ filename, content, ...(contentType ? { contentType } : {}) }]\n })\n return attachments.length ? attachments : undefined\n}\n\nclass ResendChannelAdapter implements ChannelAdapter {\n readonly providerKey = 'resend'\n readonly channelType = 'email'\n readonly capabilities = resendCapabilities\n\n async sendMessage(input: SendMessageInput): Promise<SendMessageResult> {\n const credentials = resendCredentialsSchema.parse(input.credentials)\n const meta = (input.metadata ?? {}) as Record<string, unknown>\n const to = toAddressList(meta.to).map(sanitizeHeaderValue)\n if (to.length === 0) {\n return { externalMessageId: '', status: 'failed', error: '[internal] Email send requires at least one recipient' }\n }\n const subject = headerOrUndefined(meta.subject)\n if (!subject) {\n return { externalMessageId: '', status: 'failed', error: '[internal] Email send requires a subject' }\n }\n\n const client = new Resend(credentials.apiKey)\n const resendAttachments = attachmentsFromMeta(meta.attachments)\n const replyTo = headerOrUndefined(meta.replyTo)\n const basePayload = {\n from: headerOrUndefined(meta.from) ?? credentials.fromAddress,\n to,\n subject,\n ...(replyTo ? { replyTo } : {}),\n ...(resendAttachments?.length ? { attachments: resendAttachments } : {}),\n }\n const payload: Parameters<typeof client.emails.send>[0] = input.content.html\n ? { ...basePayload, html: input.content.html, ...(input.content.text ? { text: input.content.text } : {}) }\n : { ...basePayload, text: input.content.text ?? '' }\n const result = await client.emails.send(payload)\n const errorMessage = resolveResendErrorMessage(result)\n if (errorMessage) {\n return { externalMessageId: '', status: 'failed', error: `RESEND_SEND_FAILED: ${errorMessage}` }\n }\n const sentId = (result as ResendSendResult).data?.id\n return {\n externalMessageId: sentId || `resend:${Date.now()}`,\n conversationId: input.conversationId,\n status: 'sent',\n }\n }\n\n async verifyWebhook(_input: VerifyWebhookInput): Promise<InboundMessage> {\n return { raw: {}, eventType: 'other', metadata: { reason: 'resend-system-email-outbound-only' } }\n }\n\n async getStatus(_input: GetMessageStatusInput): Promise<MessageStatus> {\n return { status: 'sent' }\n }\n\n async normalizeInbound(_raw: InboundMessage): Promise<NormalizedInboundMessage> {\n throw new Error('[internal] Resend system email adapter is outbound-only')\n }\n\n async convertOutbound(input: ConvertOutboundInput): Promise<ChannelNativeContent> {\n const meta = (input.channelMetadata ?? {}) as Record<string, unknown>\n const to = toAddressList(meta.to).map(sanitizeHeaderValue)\n const subject = headerOrUndefined(meta.subject)\n const html = input.bodyFormat === 'html' ? input.body : undefined\n const text = input.bodyFormat === 'html' ? htmlToText(input.body) : input.body\n return {\n content: {\n text,\n html,\n bodyFormat: input.bodyFormat,\n },\n metadata: {\n to,\n subject,\n from: headerOrUndefined(meta.from),\n replyTo: headerOrUndefined(meta.replyTo),\n attachments: attachmentsFromMeta(meta.attachments),\n },\n }\n }\n}\n\nconst adapter = new ResendChannelAdapter()\n\nexport function getResendChannelAdapter(): ChannelAdapter {\n return adapter\n}\n"],
5
+ "mappings": "AAAA,SAAS,cAAc;AAavB;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,0BAA0B;AACnC,SAAS,+BAA+B;AAaxC,SAAS,0BAA0B,QAAgC;AACjE,QAAM,QAAQ;AACd,MAAI,OAAO,MAAM,UAAU,SAAU,QAAO,MAAM;AAClD,MAAI,MAAM,SAAS,OAAO,MAAM,UAAU,YAAY,aAAa,MAAM,OAAO;AAC9E,UAAM,UAAW,MAAM,MAAgC;AACvD,WAAO,OAAO,YAAY,WAAW,UAAU;AAAA,EACjD;AACA,SAAO;AACT;AAEA,SAAS,kBAAkB,OAAoC;AAC7D,QAAM,OAAO,kBAAkB,KAAK;AACpC,SAAO,SAAS,SAAY,SAAY,oBAAoB,IAAI;AAClE;AAEA,SAAS,oBAAoB,OAAgD;AAC3E,MAAI,CAAC,MAAM,QAAQ,KAAK,EAAG,QAAO;AAClC,QAAM,cAAc,MAAM,QAAQ,CAAC,SAA6B;AAC9D,QAAI,CAAC,QAAQ,OAAO,SAAS,SAAU,QAAO,CAAC;AAC/C,UAAM,SAAS;AACf,UAAM,WAAW,kBAAkB,OAAO,QAAQ;AAClD,UAAM,UAAU,kBAAkB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AA,EACF;AACF;AAEA,MAAM,UAAU,IAAI,qBAAqB;AAElC,SAAS,0BAA0C;AACxD,SAAO;AACT;",
6
6
  "names": []
7
7
  }
package/jest.config.cjs CHANGED
@@ -26,7 +26,7 @@ module.exports = {
26
26
  ],
27
27
  },
28
28
  transformIgnorePatterns: [
29
- 'node_modules/(?!(@mikro-orm|kysely)/)',
29
+ 'node_modules/(?!(sanitize-html|htmlparser2|domhandler|domutils|dom-serializer|domelementtype|entities|@mikro-orm|kysely)/)',
30
30
  ],
31
31
  testMatch: ['<rootDir>/src/**/__tests__/**/*.test.(ts|tsx)'],
32
32
  passWithNoTests: true,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@open-mercato/channel-resend",
3
- "version": "0.9.1-develop.7574.1.837288eec1",
3
+ "version": "0.10.0",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -50,26 +50,26 @@
50
50
  }
51
51
  },
52
52
  "dependencies": {
53
- "@open-mercato/core": "0.9.1-develop.7574.1.837288eec1",
53
+ "@open-mercato/core": "0.10.0",
54
54
  "resend": "^6.24.0"
55
55
  },
56
56
  "peerDependencies": {
57
57
  "@mikro-orm/postgresql": "^7.0.14",
58
- "@open-mercato/ai-assistant": "0.9.1-develop.7574.1.837288eec1",
59
- "@open-mercato/shared": "0.9.1-develop.7574.1.837288eec1",
60
- "@open-mercato/ui": "0.9.1-develop.7574.1.837288eec1",
58
+ "@open-mercato/ai-assistant": "0.10.0",
59
+ "@open-mercato/shared": "0.10.0",
60
+ "@open-mercato/ui": "0.10.0",
61
61
  "react": "^19.0.0",
62
62
  "react-dom": "^19.0.0"
63
63
  },
64
64
  "devDependencies": {
65
- "@open-mercato/ai-assistant": "0.9.1-develop.7574.1.837288eec1",
66
- "@open-mercato/shared": "0.9.1-develop.7574.1.837288eec1",
67
- "@open-mercato/ui": "0.9.1-develop.7574.1.837288eec1",
65
+ "@open-mercato/ai-assistant": "0.10.0",
66
+ "@open-mercato/shared": "0.10.0",
67
+ "@open-mercato/ui": "0.10.0",
68
68
  "@types/jest": "^30.0.0",
69
69
  "@types/react": "^19.2.18",
70
70
  "@types/react-dom": "^19.2.5",
71
71
  "esbuild": "^0.28.2",
72
- "glob": "^13.0.6",
72
+ "glob": "^14.0.6",
73
73
  "jest": "^30.4.2",
74
74
  "react": "19.2.8",
75
75
  "react-dom": "19.2.8",
@@ -83,6 +83,5 @@
83
83
  "type": "git",
84
84
  "url": "https://github.com/open-mercato/open-mercato",
85
85
  "directory": "packages/channel-resend"
86
- },
87
- "stableVersion": "0.9.0"
86
+ }
88
87
  }
@@ -97,6 +97,86 @@ describe('ResendChannelAdapter', () => {
97
97
  expect(sendMock).not.toHaveBeenCalled()
98
98
  })
99
99
 
100
+ it('strips CR/LF from subject, from and replyTo before calling Resend', async () => {
101
+ const adapter = getResendChannelAdapter()
102
+
103
+ const result = await adapter.sendMessage({
104
+ content: { text: 'Hello' },
105
+ credentials: { apiKey: 'key', fromAddress: 'fallback@example.com' },
106
+ scope: { tenantId: 'tenant', organizationId: 'org' },
107
+ metadata: {
108
+ to: 'user@example.com',
109
+ subject: 'Hello\r\nBcc: attacker@example.test',
110
+ from: 'from@example.com\r\nBcc: attacker@example.test',
111
+ replyTo: 'reply@example.com\nX-Injected: yes',
112
+ },
113
+ })
114
+
115
+ expect(result).toEqual(expect.objectContaining({ status: 'sent' }))
116
+ expect(sendMock).toHaveBeenCalledWith(expect.objectContaining({
117
+ subject: 'Hello Bcc: attacker@example.test',
118
+ from: 'from@example.com Bcc: attacker@example.test',
119
+ replyTo: 'reply@example.com X-Injected: yes',
120
+ }))
121
+ })
122
+
123
+ it('returns CR/LF-free subject, from and replyTo from convertOutbound', async () => {
124
+ const adapter = getResendChannelAdapter()
125
+
126
+ const converted = await adapter.convertOutbound({
127
+ body: 'Hello',
128
+ bodyFormat: 'text',
129
+ channelMetadata: {
130
+ to: 'user@example.com',
131
+ subject: 'Hello\r\nBcc: attacker@example.test',
132
+ from: 'from@example.com\r\nBcc: attacker@example.test',
133
+ replyTo: 'reply@example.com\r\nX-Injected: yes',
134
+ },
135
+ })
136
+
137
+ expect(converted.metadata).toEqual(expect.objectContaining({
138
+ subject: 'Hello Bcc: attacker@example.test',
139
+ from: 'from@example.com Bcc: attacker@example.test',
140
+ replyTo: 'reply@example.com X-Injected: yes',
141
+ }))
142
+ })
143
+
144
+ it('strips CR/LF from attachment filename and contentType', async () => {
145
+ const adapter = getResendChannelAdapter()
146
+
147
+ await adapter.sendMessage({
148
+ content: { text: 'Hello' },
149
+ credentials: { apiKey: 'key', fromAddress: 'from@example.com' },
150
+ scope: { tenantId: 'tenant', organizationId: 'org' },
151
+ metadata: {
152
+ to: 'user@example.com',
153
+ subject: 'Hello',
154
+ attachments: [{ filename: 'a.txt\r\nX-Injected: yes', content: 'dGVzdA==', contentType: 'text/plain\r\nX-Injected: yes' }],
155
+ },
156
+ })
157
+
158
+ expect(sendMock).toHaveBeenCalledWith(expect.objectContaining({
159
+ attachments: [{ filename: 'a.txt X-Injected: yes', content: 'dGVzdA==', contentType: 'text/plain X-Injected: yes' }],
160
+ }))
161
+ })
162
+
163
+ it('still rejects a subject made only of CR/LF without calling Resend', async () => {
164
+ const adapter = getResendChannelAdapter()
165
+
166
+ const result = await adapter.sendMessage({
167
+ content: { text: 'Hello' },
168
+ credentials: { apiKey: 'key', fromAddress: 'from@example.com' },
169
+ scope: { tenantId: 'tenant', organizationId: 'org' },
170
+ metadata: { to: 'user@example.com', subject: '\r\n' },
171
+ })
172
+
173
+ expect(result).toEqual(expect.objectContaining({
174
+ status: 'failed',
175
+ error: '[internal] Email send requires a subject',
176
+ }))
177
+ expect(sendMock).not.toHaveBeenCalled()
178
+ })
179
+
100
180
  it('returns a failed result when Resend reports an error', async () => {
101
181
  sendMock.mockResolvedValueOnce({ error: { message: 'bad domain' } })
102
182
  const adapter = getResendChannelAdapter()
@@ -41,15 +41,20 @@ function resolveResendErrorMessage(result: unknown): string | null {
41
41
  return null
42
42
  }
43
43
 
44
+ function headerOrUndefined(value: unknown): string | undefined {
45
+ const text = stringOrUndefined(value)
46
+ return text === undefined ? undefined : sanitizeHeaderValue(text)
47
+ }
48
+
44
49
  function attachmentsFromMeta(value: unknown): ResendAttachment[] | undefined {
45
50
  if (!Array.isArray(value)) return undefined
46
51
  const attachments = value.flatMap((item): ResendAttachment[] => {
47
52
  if (!item || typeof item !== 'object') return []
48
53
  const record = item as Record<string, unknown>
49
- const filename = stringOrUndefined(record.filename)
54
+ const filename = headerOrUndefined(record.filename)
50
55
  const content = stringOrUndefined(record.content)
51
56
  if (!filename || !content) return []
52
- const contentType = stringOrUndefined(record.contentType)
57
+ const contentType = headerOrUndefined(record.contentType)
53
58
  return [{ filename, content, ...(contentType ? { contentType } : {}) }]
54
59
  })
55
60
  return attachments.length ? attachments : undefined
@@ -67,18 +72,19 @@ class ResendChannelAdapter implements ChannelAdapter {
67
72
  if (to.length === 0) {
68
73
  return { externalMessageId: '', status: 'failed', error: '[internal] Email send requires at least one recipient' }
69
74
  }
70
- const subject = stringOrUndefined(meta.subject)
75
+ const subject = headerOrUndefined(meta.subject)
71
76
  if (!subject) {
72
77
  return { externalMessageId: '', status: 'failed', error: '[internal] Email send requires a subject' }
73
78
  }
74
79
 
75
80
  const client = new Resend(credentials.apiKey)
76
81
  const resendAttachments = attachmentsFromMeta(meta.attachments)
82
+ const replyTo = headerOrUndefined(meta.replyTo)
77
83
  const basePayload = {
78
- from: stringOrUndefined(meta.from) ?? credentials.fromAddress,
84
+ from: headerOrUndefined(meta.from) ?? credentials.fromAddress,
79
85
  to,
80
86
  subject,
81
- ...(stringOrUndefined(meta.replyTo) ? { replyTo: stringOrUndefined(meta.replyTo) } : {}),
87
+ ...(replyTo ? { replyTo } : {}),
82
88
  ...(resendAttachments?.length ? { attachments: resendAttachments } : {}),
83
89
  }
84
90
  const payload: Parameters<typeof client.emails.send>[0] = input.content.html
@@ -112,7 +118,7 @@ class ResendChannelAdapter implements ChannelAdapter {
112
118
  async convertOutbound(input: ConvertOutboundInput): Promise<ChannelNativeContent> {
113
119
  const meta = (input.channelMetadata ?? {}) as Record<string, unknown>
114
120
  const to = toAddressList(meta.to).map(sanitizeHeaderValue)
115
- const subject = stringOrUndefined(meta.subject)
121
+ const subject = headerOrUndefined(meta.subject)
116
122
  const html = input.bodyFormat === 'html' ? input.body : undefined
117
123
  const text = input.bodyFormat === 'html' ? htmlToText(input.body) : input.body
118
124
  return {
@@ -124,8 +130,8 @@ class ResendChannelAdapter implements ChannelAdapter {
124
130
  metadata: {
125
131
  to,
126
132
  subject,
127
- from: stringOrUndefined(meta.from),
128
- replyTo: stringOrUndefined(meta.replyTo),
133
+ from: headerOrUndefined(meta.from),
134
+ replyTo: headerOrUndefined(meta.replyTo),
129
135
  attachments: attachmentsFromMeta(meta.attachments),
130
136
  },
131
137
  }