blob: 82c974bc6f7d91d4b6524f599961b2b240b645fc (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
import type { Nullable } from '../../../types';
import { fetchGraphQL, getGraphQLUrl } from '../../../utils/helpers';
export type SendEmail = {
clientMutationId: Nullable<string>;
message: string;
origin: string;
replyTo: string;
sent: boolean;
};
export type SendEmailResponse = {
sendEmail: SendEmail;
};
const sendEmailMutation = `mutation SendEmail($input: SendEmailInput!) {
sendEmail(input: $input) {
clientMutationId
message
origin
replyTo
sent
to
}
}`;
export type SendEmailInput = {
body: string;
clientMutationId: string;
replyTo: string;
subject?: string;
};
/**
* Send an email using GraphQL API.
*
* @param {SendEmailInput} input - The mail input.
* @returns {Promise<SendEmail>} The mutation response.
*/
export const sendEmail = async (input: SendEmailInput): Promise<SendEmail> => {
const response = await fetchGraphQL<SendEmailResponse>({
query: sendEmailMutation,
url: getGraphQLUrl(),
variables: { input },
});
return response.sendEmail;
};
|