/** * Send Mitchell Allen his portal password-set link + a note that his e-sign * authorization emails are now on the way (after the SMTP fix). CC justin. * Run: docker exec performancewest-api-1 node /app/scripts/rescue-mitchell-email.mjs */ import pg from "pg"; import crypto from "crypto"; import nodemailer from "nodemailer"; const EMAIL = "mitchell@allenscrapmetal.com"; const CC = "justin@performancewest.net"; const SITE = process.env.DOMAIN ? `https://${process.env.DOMAIN}` : "https://performancewest.net"; const pool = new pg.Pool({ connectionString: process.env.DATABASE_URL }); const mailer = nodemailer.createTransport({ host: process.env.SMTP_HOST || "co.carrierone.com", port: parseInt(process.env.SMTP_PORT || "587", 10), secure: false, auth: { user: process.env.SMTP_USER, pass: process.env.SMTP_PASS }, }); const FROM = process.env.SMTP_FROM || "Performance West "; const cust = await pool.query(`SELECT id, name FROM customers WHERE email=$1`, [EMAIL]); if (!cust.rows.length) { console.log("no customers row for", EMAIL); process.exit(1); } const customer = cust.rows[0]; const firstName = (customer.name || "there").split(" ")[0]; const { rows: orders } = await pool.query( `SELECT order_number, service_name FROM compliance_orders WHERE customer_email=$1 ORDER BY created_at`, [EMAIL]); const token = crypto.randomBytes(32).toString("hex"); await pool.query( `INSERT INTO password_reset_tokens (customer_id, token, expires_at) VALUES ($1,$2,$3)`, [customer.id, token, new Date(Date.now() + 7 * 24 * 60 * 60 * 1000)], ); const resetLink = `${SITE}/account/reset-password?token=${token}`; const orderList = orders.map(o => `
  • ${o.service_name} (${o.order_number})
  • `).join(""); await mailer.sendMail({ from: FROM, to: EMAIL, cc: CC, subject: "Your Performance West login + signature requests are on the way", html: `

    You're all set, ${firstName}

    Thanks for your order. We had a delivery issue that kept our earlier emails from reaching you - that's fixed now, so here is everything you need.

    1. Set your password to log in (valid for 7 days):

    Set my password →

    Or paste this link: ${resetLink}

    2. Sign your authorizations. We're sending you a separate signature request for each filing below. Each filing begins once you sign it - for the MCS-150 and USDOT reactivation we prepare the form and you review/sign before we submit to FMCSA.

    You can also track everything in your portal once you log in. Questions? Reply here or call 1-888-411-0383.

    Performance West Inc. · performancewest.net · 1-888-411-0383

    `, text: `Hi ${firstName}, set your password to log in: ${resetLink} (valid 7 days). You'll also receive a signature request for each filing: ${orders.map(o => o.service_name + " (" + o.order_number + ")").join("; ")}. Each filing begins once you sign. Questions? 1-888-411-0383.`, }); console.log(`[rescue] login + signature note sent to ${EMAIL} (cc ${CC}) for ${orders.length} orders`); await pool.end();