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.
This commit is contained in:
parent
4745de1bce
commit
54974584b1
1 changed files with 8 additions and 3 deletions
|
|
@ -307,7 +307,12 @@ async function main() {
|
||||||
console.log(`[fh-deposit] Deposit account "${mapping.deposit_account_name}" -> ${depositAccountId}`);
|
console.log(`[fh-deposit] Deposit account "${mapping.deposit_account_name}" -> ${depositAccountId}`);
|
||||||
|
|
||||||
// 3. Build + post payments
|
// 3. Build + post payments
|
||||||
const client = getQboClient();
|
// Defer QBO client construction until first live write — dry-run needs no QBO credentials.
|
||||||
|
let client: ReturnType<typeof getQboClient> | null = null;
|
||||||
|
const getClient = () => {
|
||||||
|
if (!client) client = getQboClient();
|
||||||
|
return client;
|
||||||
|
};
|
||||||
const paymentResults: Array<{ seq: number; amount: number; paymentId: string }> = [];
|
const paymentResults: Array<{ seq: number; amount: number; paymentId: string }> = [];
|
||||||
|
|
||||||
for (const check of mapping.checks) {
|
for (const check of mapping.checks) {
|
||||||
|
|
@ -327,7 +332,7 @@ async function main() {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
const created = await client.createPayment(payload);
|
const created = await getClient().createPayment(payload);
|
||||||
console.log(` -> Payment ${created.Id} created`);
|
console.log(` -> Payment ${created.Id} created`);
|
||||||
applied.payments[seqKey] = { qbo_payment_id: created.Id, applied_at: new Date().toISOString() };
|
applied.payments[seqKey] = { qbo_payment_id: created.Id, applied_at: new Date().toISOString() };
|
||||||
saveApplied(appliedPath, applied);
|
saveApplied(appliedPath, applied);
|
||||||
|
|
@ -350,7 +355,7 @@ async function main() {
|
||||||
console.log(` PAYLOAD: ${JSON.stringify(depositPayload)}`);
|
console.log(` PAYLOAD: ${JSON.stringify(depositPayload)}`);
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
const created = await client.createDeposit(depositPayload);
|
const created = await getClient().createDeposit(depositPayload);
|
||||||
console.log(` -> Deposit ${created.Id} created`);
|
console.log(` -> Deposit ${created.Id} created`);
|
||||||
applied.deposit = { qbo_deposit_id: created.Id, applied_at: new Date().toISOString() };
|
applied.deposit = { qbo_deposit_id: created.Id, applied_at: new Date().toISOString() };
|
||||||
saveApplied(appliedPath, applied);
|
saveApplied(appliedPath, applied);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue