bump: email service

Signed-off-by: Kenneth Obsequio <k80308392@gmail.com>
This commit is contained in:
2026-07-14 13:58:14 +08:00
parent a7a72096a5
commit cd2ec55d82
+5 -7
View File
@@ -26,8 +26,7 @@ const axios = require('axios');
const { OAuth2Client } = require('google-auth-library'); const { OAuth2Client } = require('google-auth-library');
const { emailTemplates } = require('../data/email_body.data'); const { emailTemplates } = require('../data/email_body.data');
const GMAIL_SEND_URL = 'https://gmail.googleapis.com/gmail/v1/users/me/messages/send'; const GMAIL_SEND_URL = 'https://gmail.googleapis.com/gmail/v1/users/me/messages/send';
const GMAIL_PROFILE_URL = 'https://gmail.googleapis.com/gmail/v1/users/me/profile';
// Lazily initialised so the module can be required before env is loaded. // Lazily initialised so the module can be required before env is loaded.
let _oauth2Client; let _oauth2Client;
@@ -85,10 +84,9 @@ const sendEmail = async ({ to, type, data = {} }) => {
} }
}; };
// Confirms the refresh token is valid and the Gmail API is reachable. // Confirms the refresh token is valid and Gmail's OAuth endpoint is reachable.
const ping = async () => { // Deliberately doesn't call a Gmail read endpoint (e.g. users.getProfile) — the
const accessToken = await getAccessToken(); // refresh token is scoped to gmail.send only, which doesn't grant read access.
await axios.get(GMAIL_PROFILE_URL, { headers: { Authorization: `Bearer ${accessToken}` } }); const ping = () => getAccessToken();
};
module.exports = { sendEmail, ping }; module.exports = { sendEmail, ping };