OUT-3700: remove find-or-map invoice logic from webhook handlers#243
OUT-3700: remove find-or-map invoice logic from webhook handlers#243SandipBajracharya merged 2 commits intomasterfrom
Conversation
The find-or-map fallback (1ed7b57) lazily inserted qb_invoice_sync rows from inside live webhook handlers when QBO already had the invoice. Drop that path from webhookInvoiceCreated/Paid/Voided and from the QBO-present branch of handleInvoiceDeleted; restore the original behavior where missing local mapping throws an APIError so the webhook-level catch records a FAILED row and the resync cron retries once a CREATED resync establishes the mapping. Kept intentionally: - checkIfInvoiceExistsInQBO body unchanged; serves the syncMissedInvoices cron path where mapping-on-find is desirable. - findOrMapInvoiceFromQBO retained as a private helper (only caller is checkIfInvoiceExistsInQBO now); dropped its unused qbInvoice param. - handleInvoiceDeleted's QBO-absent branch (soft-delete prior sync logs + record pre-soft-deleted DELETED log) stays. - OUT-3644 onConflictDoNothing race guard and OUT-3655 PENDING-status checks on CREATED log lookups are independent and unchanged. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Greptile SummaryThis PR surgically reverts the find-or-map fallback introduced in
Confidence Score: 5/5Safe to merge — the revert is surgical and the webhook catch blocks in webhook.service.ts correctly transition PENDING claims to FAILED for all four affected event types. All changed call sites correctly use No files require special attention. Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[Copilot Webhook Event\nPAID / VOIDED / DELETED] --> B{Local mapping\nin qb_invoice_sync?}
B -- Yes --> C[Process event\nwrite SUCCESS log]
B -- No --> D[throw APIError NOT_FOUND]
D --> E[webhook.service.ts catch\npushFailedInvoiceToSyncLog\nstatus = FAILED]
F[CREATE webhook] --> G{Mapping present?}
G -- Yes --> H[Skip / idempotent]
G -- No --> I[Create invoice in QBO\nwrite mapping row\nwrite SUCCESS CREATED log]
I --> J{FAILED PAID/VOIDED/DELETED\nlogs in queue?}
J -- Yes --> K[Resync cron retries\nNow finds mapping - SUCCESS]
J -- No --> L[Done]
subgraph Cron Path
M[syncMissedInvoices cron] --> N[checkIfInvoiceExistsInQBO]
N --> O[findOrMapInvoiceFromQBO\nmaps manually-created QBO invoices]
end
style D fill:#f66,color:#fff
style E fill:#f99,color:#fff
style C fill:#6a6,color:#fff
style K fill:#6a6,color:#fff
Reviews (1): Last reviewed commit: "revert(OUT-3700): remove find-or-map inv..." | Re-trigger Greptile |
priosshrsth
left a comment
There was a problem hiding this comment.
lgtm. But I think we can work on idenfiying pre existing invoice with the invoice number and show error accordingly in another PR.
Note the DocNumber-collision failure mode that motivates the revert and points future readers at the surviving syncMissedInvoices cron caller. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Summary
Surgical revert of
1ed7b57's find-or-map fallback in the live webhook handlers, restoring the original behavior where missing local mapping throwsAPIErrorso the webhook-level catch records a FAILED row and the resync cron retries once a CREATED resync establishes the mapping.Reverted (the find-or-map plumbing):
webhookInvoiceCreated: dropped early-exit short-circuitwebhookInvoicePaid/webhookInvoiceVoided: dropped lazy mapping fallback; now throwsAPIError(NOT_FOUND)on missing mappinghandleInvoiceDeleted: dropped find-or-map call in the "QBO present + no local mapping" branch; now throwsAPIError(NOT_FOUND)qbInvoiceparam fromfindOrMapInvoiceFromQBOKept intentionally:
checkIfInvoiceExistsInQBObody unchanged — used by thesyncMissedInvoicescron path where mapping-on-find is desirablefindOrMapInvoiceFromQBOretained as a private helper (only caller ischeckIfInvoiceExistsInQBO)handleInvoiceDeleted's "QBO absent" branch (soft-delete prior sync logs + record pre-soft-deleted DELETED log)onConflictDoNothingrace guard and OUT-3655 PENDING-status checks on CREATED log lookups — independent improvements, untouchedRecovery flow: throw →
webhook.service.tscatch transitions PENDING claim → FAILED viaupdateOrCreateQBSyncLog→ resync cron retries → succeeds once CREATED resync populatesqb_invoice_sync.Linear: https://linear.app/assemblycom/issue/OUT-3700
Test plan
🤖 Generated with Claude Code