@devvai/devv-code-backend
Version:
Backend SDK for Devv Code - Provides authentication, data management, email and AI capabilities
37 lines (36 loc) • 1.41 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.DevvEmail = void 0;
const device_1 = require("./device");
const session_1 = require("./session");
const constants_1 = require("./constants");
class DevvEmail {
async sendEmail(options) {
if (!options.from || !options.to || options.to.length === 0 || !options.subject) {
throw new Error('Missing required fields: from, to, and subject are required');
}
if (!options.html && !options.text) {
throw new Error('Either html or text content must be provided');
}
const deviceId = (0, device_1.getEncryptedDeviceId)();
const sid = (0, session_1.getSid)();
const headers = {
'Content-Type': 'application/json',
'Device-Id': deviceId
};
if (sid) {
headers['sid'] = sid;
}
const response = await fetch(`${constants_1.BASE_URL}api/v1/email/send`, {
method: 'POST',
headers,
body: JSON.stringify(options)
});
if (!response.ok) {
const error = await response.json().catch(() => ({ error: { message: 'Failed to send email' } }));
throw new Error(error.error?.message || `Failed to send email (Status: ${response.status})`);
}
return await response.json();
}
}
exports.DevvEmail = DevvEmail;
;