Fix: update dependencies, remove sparkpost-node

This commit removes the sparkpost-node and switches to using a raw api call using fetch. This commit also updates the dependency react-email.
This commit is contained in:
Aaron William Po
2023-11-12 17:43:48 -05:00
parent 24e245fc6f
commit b939219c67
4 changed files with 448 additions and 1238 deletions

View File

@@ -1,6 +0,0 @@
import SparkPost from 'sparkpost';
import { SPARKPOST_API_KEY } from '../env';
const client = new SparkPost(SPARKPOST_API_KEY);
export default client;

View File

@@ -1,5 +1,4 @@
import { SPARKPOST_SENDER_ADDRESS } from '../env';
import client from './client';
import { SPARKPOST_API_KEY, SPARKPOST_SENDER_ADDRESS } from '../env';
interface EmailParams {
address: string;
@@ -11,10 +10,26 @@ interface EmailParams {
const sendEmail = async ({ address, text, html, subject }: EmailParams) => {
const from = SPARKPOST_SENDER_ADDRESS;
await client.transmissions.send({
content: { from, html, subject, text },
const data = {
recipients: [{ address }],
content: { from, subject, text, html },
};
const transmissionsEndpoint = 'https://api.sparkpost.com/api/v1/transmissions';
const response = await fetch(transmissionsEndpoint, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Accept: 'application/json',
Authorization: SPARKPOST_API_KEY,
},
body: JSON.stringify(data),
});
if (response.status !== 200) {
throw new Error(`Sparkpost API returned status code ${response.status}`);
}
};
export default sendEmail;