Skip to content

Commit 4a711e9

Browse files
committed
Update some deps
1 parent fe1bc8c commit 4a711e9

File tree

3 files changed

+264
-513
lines changed

3 files changed

+264
-513
lines changed

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
"prepare": "husky"
5353
},
5454
"dependencies": {
55-
"@apollo/client": "4.1.4",
55+
"@apollo/client": "4.1.5",
5656
"@babylonjs/core": "8.52.0",
5757
"@babylonjs/gui": "8.52.0",
5858
"@babylonjs/loaders": "8.52.0",
@@ -66,15 +66,15 @@
6666
"@codersrank/work-experience": "0.9.8",
6767
"@contentful/rich-text-html-renderer": "17.1.6",
6868
"@date-fns/utc": "2.1.1",
69-
"@getbrevo/brevo": "3.0.1",
69+
"@getbrevo/brevo": "4.0.1",
7070
"@serwist/next": "9.5.6",
7171
"@vercel/analytics": "1.6.1",
7272
"@vercel/speed-insights": "1.3.1",
7373
"animateme": "2.4.2",
7474
"async-array-prototype": "1.1.1",
7575
"attr-i18n": "1.0.0",
7676
"babylonjs-gltf2interface": "8.52.0",
77-
"contentful": "11.10.3",
77+
"contentful": "11.10.4",
7878
"d3": "7.9.0",
7979
"date-fns": "4.1.0",
8080
"dator": "2.0.0",
@@ -157,7 +157,7 @@
157157
"cloudinary": "2.9.0",
158158
"commander": "14.0.3",
159159
"dotenv": "17.3.1",
160-
"eslint": "10.0.0",
160+
"eslint": "10.0.1",
161161
"eslint-config-prettier": "10.1.8",
162162
"eslint-plugin-import": "2.32.0",
163163
"eslint-plugin-jest": "29.15.0",
@@ -200,7 +200,7 @@
200200
"postcss-utilities": "0.8.4",
201201
"postcss-watch-folder": "2.0.0",
202202
"prettier": "3.8.1",
203-
"puppeteer": "24.37.3",
203+
"puppeteer": "24.37.5",
204204
"sass": "1.97.3",
205205
"serwist": "9.5.6",
206206
"stylelint": "17.3.0",

src/pages/api/mail.ts

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@ import { join } from 'node:path';
33

44
import type { NextApiRequest, NextApiResponse } from 'next';
55

6-
import { SendSmtpEmail, TransactionalEmailsApi } from '@getbrevo/brevo';
6+
import { BrevoClient, BrevoError } from '@getbrevo/brevo';
7+
import { TooManyRequestsError, UnauthorizedError } from '@getbrevo/brevo/dist/cjs/api';
78
import mjml2html from 'mjml';
89

910
import type { FormData } from '@scripts/types';
1011

11-
const sendSMTPEmail = new SendSmtpEmail();
12-
const transactionalEmailsAPI = new TransactionalEmailsApi();
13-
14-
transactionalEmailsAPI['authentications']['apiKey'].apiKey = process.env.SENDINBLUE_API_KEY ?? '';
12+
const brevo = new BrevoClient({
13+
apiKey: process.env.SENDINBLUE_API_KEY ?? ''
14+
});
1515

1616
const emailTemplate = readFileSync(join(process.cwd(), 'email', 'contact.mjml'), 'utf8');
1717

@@ -38,18 +38,28 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
3838

3939
const htmlContent = interpolateTemplate(emailTemplate, data);
4040

41-
sendSMTPEmail.to = [{ email: 'hi@atanas.info' }];
42-
sendSMTPEmail.sender = { email: data.email };
43-
sendSMTPEmail.subject = 'New contact form submission from https://atanas.info';
44-
sendSMTPEmail.htmlContent = htmlContent;
45-
4641
try {
47-
result = await transactionalEmailsAPI.sendTransacEmail(sendSMTPEmail);
42+
result = await brevo.transactionalEmails.sendTransacEmail({
43+
to: [{ email: 'hi@atanas.info' }],
44+
sender: { email: data.email },
45+
subject: 'New contact form submission from https://atanas.info',
46+
htmlContent: htmlContent
47+
});
4848

4949
return res.status(200).json(result);
5050
} catch (error) {
5151
result = { error };
5252

53+
if (error instanceof UnauthorizedError) {
54+
console.error('Invalid API key');
55+
} else if (error instanceof TooManyRequestsError) {
56+
const retryAfter = (error.rawResponse?.headers as any)['retry-after'];
57+
58+
console.error(`Rate limited. Retry after ${retryAfter} seconds`);
59+
} else if (error instanceof BrevoError) {
60+
console.error(`API Error ${error.statusCode}:`, error.message);
61+
}
62+
5363
return res.status(400).json(result);
5464
}
5565
}

0 commit comments

Comments
 (0)