mirror of
https://github.com/directus/directus.git
synced 2026-04-25 03:00:53 -04:00
Api: Emit filter for email.send (#23024)
Co-authored-by: Pascal Jufer <pascal-jufer@bluewin.ch>
This commit is contained in:
6
.changeset/stale-chicken-perform.md
Normal file
6
.changeset/stale-chicken-perform.md
Normal file
@@ -0,0 +1,6 @@
|
||||
---
|
||||
"@directus/api": minor
|
||||
"@directus/app": patch
|
||||
---
|
||||
|
||||
Introduced the `email.send` filter event, allowing to modify email options via Flows or Custom Extensions
|
||||
@@ -12,6 +12,7 @@ import { useLogger } from '../../logger/index.js';
|
||||
import getMailer from '../../mailer.js';
|
||||
import type { AbstractServiceOptions } from '../../types/index.js';
|
||||
import { Url } from '../../utils/url.js';
|
||||
import emitter from '../../emitter.js';
|
||||
|
||||
const env = useEnv();
|
||||
const logger = useLogger();
|
||||
@@ -52,8 +53,17 @@ export class MailService {
|
||||
}
|
||||
}
|
||||
|
||||
async send<T>(options: EmailOptions): Promise<T> {
|
||||
const { template, ...emailOptions } = options;
|
||||
async send<T>(options: EmailOptions): Promise<T | null> {
|
||||
const payload = await emitter.emitFilter(`email.send`, options, {
|
||||
database: getDatabase(),
|
||||
schema: null,
|
||||
accountability: null,
|
||||
});
|
||||
|
||||
if (!payload) return null;
|
||||
|
||||
const { template, ...emailOptions } = payload;
|
||||
|
||||
let { html } = options;
|
||||
|
||||
const defaultTemplateData = await this.getDefaultTemplateData();
|
||||
|
||||
@@ -134,6 +134,7 @@ export function getTriggers() {
|
||||
'auth.create',
|
||||
'auth.update',
|
||||
'authenticate',
|
||||
'email.send',
|
||||
],
|
||||
font: 'monospace',
|
||||
},
|
||||
|
||||
@@ -205,6 +205,7 @@ export default ({ embed }, { env }) => {
|
||||
| `auth.create`<sup>[1]</sup> | The created user | `identifier`, `provider`, `providerPayload` |
|
||||
| `auth.update`<sup>[2]</sup> | The updated auth token<sup>[3]</sup> | `identifier`, `provider`, `providerPayload` |
|
||||
| `authenticate` | The empty accountability object | `req` |
|
||||
| `email.send` | The email payload | -- |
|
||||
| `(<collection>.)items.query` | The items query | `collection` |
|
||||
| `(<collection>.)items.read` | The read item | `query`, `collection` |
|
||||
| `(<collection>.)items.create` | The new item | `collection` |
|
||||
|
||||
Reference in New Issue
Block a user