fix(notify-client): don't send undefined emailOptions

Only include emailOptions object when from or replyTo is provided,
preventing validation errors when these optional fields are not set.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Till-JS 2026-01-29 23:25:46 +01:00
parent 971e269fbd
commit 7ffee52408

View file

@ -36,7 +36,7 @@ export class NotifyClient {
* Send an email notification
*/
async sendEmail(options: SendEmailOptions): Promise<NotificationResponse> {
return this.send({
const payload: Record<string, unknown> = {
channel: 'email',
appId: this.appId,
recipient: options.to,
@ -44,13 +44,19 @@ export class NotifyClient {
subject: options.subject,
body: options.body,
data: options.data,
emailOptions: {
from: options.from,
replyTo: options.replyTo,
},
priority: options.priority,
externalId: options.externalId,
});
};
// Only include emailOptions if from or replyTo is provided
if (options.from || options.replyTo) {
payload.emailOptions = {
...(options.from && { from: options.from }),
...(options.replyTo && { replyTo: options.replyTo }),
};
}
return this.send(payload);
}
/**
@ -117,7 +123,7 @@ export class NotifyClient {
* Schedule an email notification
*/
async scheduleEmail(options: SendEmailOptions & ScheduleOptions): Promise<NotificationResponse> {
return this.schedule({
const payload: Record<string, unknown> = {
channel: 'email',
appId: this.appId,
recipient: options.to,
@ -125,17 +131,23 @@ export class NotifyClient {
subject: options.subject,
body: options.body,
data: options.data,
emailOptions: {
from: options.from,
replyTo: options.replyTo,
},
priority: options.priority,
externalId: options.externalId,
scheduledFor:
options.scheduledFor instanceof Date
? options.scheduledFor.toISOString()
: options.scheduledFor,
});
};
// Only include emailOptions if from or replyTo is provided
if (options.from || options.replyTo) {
payload.emailOptions = {
...(options.from && { from: options.from }),
...(options.replyTo && { replyTo: options.replyTo }),
};
}
return this.schedule(payload);
}
/**