TaxHacker icon indicating copy to clipboard operation
TaxHacker copied to clipboard

draft - feat: Paperless-ngx integration (import/export)

Open lcrostarosa opened this issue 8 months ago • 0 comments

Summary

Adds bidirectional integration with Paperless-ngx, a self-hosted document management system. Closes #39.

  • Import: Browse, search, and select documents from Paperless-ngx. Downloads files into TaxHacker's unsorted queue for AI analysis.
  • Export: Upload transaction files to Paperless-ngx with tag and correspondent mapping from the bulk actions menu.
  • Settings: New settings page at /settings/paperless with URL, API token, enable toggle, and connection test button.
  • Deduplication: Tracks paperlessDocumentId on the File model to prevent duplicate imports/exports.
  • Security: All API calls are server-side (server actions), URL validated for SSRF prevention, 30s request timeouts.

New files

  • lib/paperless/ — Typed API client (native fetch, auth, pagination, error handling)
  • app/(app)/settings/paperless/ — Settings page + test connection action
  • app/(app)/import/paperless/ — Import page + server actions
  • app/(app)/export/paperless/ — Export server actions
  • components/settings/paperless-settings-form.tsx — Settings form
  • components/import/paperless.tsx — Import UI (browse, search, select, paginate)
  • components/export/paperless-export-dialog.tsx — Export dialog with tag/correspondent selection
  • docs/paperless-ngx.md — Full documentation
  • Prisma migration adding paperless_document_id to files table

Modified files

  • prisma/schema.prisma — paperlessDocumentId field + index on File model
  • forms/settings.ts — Paperless fields in settings Zod schema
  • app/(app)/settings/layout.tsx — "Paperless-ngx" in settings nav
  • models/files.ts — getFileByPaperlessDocumentId() query
  • components/sidebar/sidebar.tsx — "Import from Paperless" sidebar link
  • components/transactions/bulk-actions.tsx — "Export to Paperless" button
  • components/transactions/list.tsx + app/(app)/transactions/page.tsx — Pass Paperless enabled flag

Test plan

  • [ ] Run npx prisma migrate dev — migration applies cleanly
  • [ ] npm run build — no type errors (verified)
  • [ ] Settings: configure URL + token, save, test connection shows document count
  • [ ] Import: browse documents with search/pagination, import selected, verify in /unsorted
  • [ ] Import: re-import same documents — verify they are skipped (deduplication)
  • [ ] Export: select transactions, export to Paperless with tags/correspondent, verify in Paperless
  • [ ] Export: re-export same files — verify already-uploaded files are skipped
  • [ ] Sidebar shows "Import from Paperless" link
  • [ ] Bulk actions show "Export to Paperless" only when Paperless is configured

🤖 Generated with Claude Code

lcrostarosa avatar Mar 31 '26 03:03 lcrostarosa