/* eslint-disable */ // Debug the logo fetch path end-to-end. Run via `npx tsx --tsconfig tsconfig.json scripts/dev/debug-logo.ts`. import { fetchLetterhead, letterheadLogoUrl } from "@/lib/letterhead"; import { renderQuotePdf } from "@/lib/pdf/render"; import type { Quote, QuoteItem, Customer } from "@/lib/types"; import fs from "fs"; async function main() { console.log("=== Fetching CNL letterhead ==="); const lh = await fetchLetterhead("CNL"); console.log(" display_name:", lh.display_name); console.log(" logo field:", JSON.stringify(lh.logo)); console.log(" collectionId:", lh.collectionId); const url = letterheadLogoUrl(lh); console.log(" URL:", url); if (!url) { console.log("NO URL"); return; } console.log("=== Fetching logo ==="); const res = await fetch(url); console.log(" status:", res.status); console.log(" content-type:", res.headers.get("content-type")); console.log(" content-length:", res.headers.get("content-length")); if (!res.ok) { console.log("FETCH FAILED"); return; } const bytes = Buffer.from(await res.arrayBuffer()); console.log(" bytes received:", bytes.length); fs.writeFileSync("/tmp/debug-logo.bin", bytes); const ct = res.headers.get("content-type") || "image/png"; const dataUri = `data:${ct};base64,${bytes.toString("base64")}`; console.log("=== Data URI ==="); console.log(" prefix:", dataUri.slice(0, 80) + "..."); console.log(" total length:", dataUri.length); console.log("=== Rendering PDF with logo ==="); const mockQuote = { id: "q1", collectionId: "pbc_quotes", collectionName: "quotes", created: new Date().toISOString(), updated: new Date().toISOString(), quote_number: "DEBUG", quote_reference: "", external_number: "", rfq_number: "", markup: 0, customer: "c1", company: "", claimed_by: "", description: "", status: "new", approved_by: "", notes: "", email_sender: "", email_subject: "", email_body: "", has_attachments: false, company_letterhead: "CNL", email_delivered: false, email_delivered_at: "", email_received_at: "", email_opened: false, email_opened_at: "", email_tracking_id: "", has_new_reply: false, last_reply_at: "", email_failed_at: "", pdf_generated_at: "", email_message_id: "", } as unknown as Quote; const mockCustomer = { id: "c1", collectionId: "pbc_customers", collectionName: "customers", created: new Date().toISOString(), updated: new Date().toISOString(), customer: "Test Customer", email: "test@test.com", alternative_email: "", buyer_email: "", number: "", company: "", dateadded: "", lastvisiteddate: "", rep: "", coordinates: "", description: "", } as Customer; const mockItem = { id: "i1", collectionId: "pbc_quote_items", collectionName: "quote_items", created: new Date().toISOString(), updated: new Date().toISOString(), quote: "q1", description: "Test item", quote_number: "DEBUG", quote_reference: "", quantity: 1, supplier: "", cost_price: 0, selling_price: 100, notes: "", is_processed: true, markup: 0, quote_pdf_id: "", user_edited: true, } as QuoteItem; const buf = await renderQuotePdf({ quote: mockQuote, items: [mockItem], customer: mockCustomer, letterhead: lh, logoDataUri: dataUri, }); fs.writeFileSync("/tmp/debug-pdf.pdf", buf); console.log(" PDF bytes:", buf.length); console.log("Saved /tmp/debug-pdf.pdf"); } main().catch((err) => { console.error("FAIL:", err); process.exit(1); });