"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.sendTicketEmail = sendTicketEmail;
exports.logTicketEmail = logTicketEmail;
const firebase_functions_1 = require("firebase-functions");
const resend_1 = require("resend");
const resend = new resend_1.Resend(process.env.EMAIL_API_KEY);
const APP_URL = process.env.APP_URL || "https://staging.blackcanyontickets.com";
/**
* Sends ticket confirmation email with QR codes
*/
async function sendTicketEmail({ to, eventName, tickets, organizationName = "Black Canyon Tickets", }) {
try {
const ticketList = tickets
.map((ticket) => `
${ticket.ticketTypeName}
Ticket ID: ${ticket.ticketId}
Event: ${eventName}
Date: ${new Date(ticket.startAt).toLocaleString()}
QR Code: ${ticket.qr}
`)
.join("");
const html = `
Your Tickets - ${eventName}
${organizationName}
Your ticket confirmation
Your Tickets for ${eventName}
Thank you for your purchase! Your tickets are ready. Please save this email for your records.
${ticketList}
Important Information
- Present your QR code at the venue for entry
- Each ticket can only be scanned once
- Arrive early to avoid delays
- Contact support if you have any issues
Need help? Contact us at support@blackcanyontickets.com
`;
const text = `
Your Tickets for ${eventName}
Thank you for your purchase! Your tickets are ready:
${tickets
.map((ticket) => `
Ticket: ${ticket.ticketTypeName}
ID: ${ticket.ticketId}
QR: ${ticket.qr}
View: ${APP_URL}/t/${ticket.ticketId}
`)
.join("\n")}
Important:
- Present your QR code at the venue for entry
- Each ticket can only be scanned once
- Arrive early to avoid delays
Need help? Contact support@blackcanyontickets.com
`;
await resend.emails.send({
from: "tickets@blackcanyontickets.com",
to,
subject: `Your tickets – ${eventName}`,
html,
text,
});
firebase_functions_1.logger.info("Ticket email sent successfully", {
to,
eventName,
ticketCount: tickets.length,
});
}
catch (error) {
firebase_functions_1.logger.error("Failed to send ticket email", {
error: error instanceof Error ? error.message : String(error),
to,
eventName,
ticketCount: tickets.length,
});
throw error;
}
}
/**
* Development helper - logs email instead of sending
*/
async function logTicketEmail(options) {
firebase_functions_1.logger.info("DEV: Would send ticket email", {
to: options.to,
eventName: options.eventName,
tickets: options.tickets.map((t) => ({
id: t.ticketId,
qr: t.qr,
type: t.ticketTypeName,
url: `${APP_URL}/t/${t.ticketId}`,
})),
});
}
//# sourceMappingURL=email.js.map