From 54974584b1adcfab4459e7d51a4ed6edc0fe0959 Mon Sep 17 00:00:00 2001 From: lorentz Date: Tue, 19 May 2026 00:38:47 -0400 Subject: [PATCH] fix(260519-0oz-02): defer QBO client construction in dry-run to avoid credential requirement In dry-run mode the script makes zero QBO writes, so QboClient should not be instantiated (which would throw if QBO_CLIENT_ID etc are unset). Replace eager getQboClient() call with a lazy getClient() wrapper that constructs QboClient only when the first live POST is about to be made. --- scripts/apply-fh-deposit.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/scripts/apply-fh-deposit.ts b/scripts/apply-fh-deposit.ts index a21ca0f..7b21faf 100644 --- a/scripts/apply-fh-deposit.ts +++ b/scripts/apply-fh-deposit.ts @@ -307,7 +307,12 @@ async function main() { console.log(`[fh-deposit] Deposit account "${mapping.deposit_account_name}" -> ${depositAccountId}`); // 3. Build + post payments - const client = getQboClient(); + // Defer QBO client construction until first live write — dry-run needs no QBO credentials. + let client: ReturnType | null = null; + const getClient = () => { + if (!client) client = getQboClient(); + return client; + }; const paymentResults: Array<{ seq: number; amount: number; paymentId: string }> = []; for (const check of mapping.checks) { @@ -327,7 +332,7 @@ async function main() { continue; } try { - const created = await client.createPayment(payload); + const created = await getClient().createPayment(payload); console.log(` -> Payment ${created.Id} created`); applied.payments[seqKey] = { qbo_payment_id: created.Id, applied_at: new Date().toISOString() }; saveApplied(appliedPath, applied); @@ -350,7 +355,7 @@ async function main() { console.log(` PAYLOAD: ${JSON.stringify(depositPayload)}`); } else { try { - const created = await client.createDeposit(depositPayload); + const created = await getClient().createDeposit(depositPayload); console.log(` -> Deposit ${created.Id} created`); applied.deposit = { qbo_deposit_id: created.Id, applied_at: new Date().toISOString() }; saveApplied(appliedPath, applied);