feat: add attachment upload, list, and download commands#6
Open
illumitry-mf wants to merge 2 commits intoXeroAPI:mainfrom
Open
feat: add attachment upload, list, and download commands#6illumitry-mf wants to merge 2 commits intoXeroAPI:mainfrom
illumitry-mf wants to merge 2 commits intoXeroAPI:mainfrom
Conversation
Adds `attachments` sub-commands to the seven resource types that support file attachments via the Xero Accounting API: invoices, credit-notes, bank-transactions, quotes, contacts, accounts, and manual-journals. ## Commands added Each resource gains three new sub-commands: xero <resource> attachments upload --<resource>-id <ID> --file <path> xero <resource> attachments list --<resource>-id <ID> xero <resource> attachments download --<resource>-id <ID> --attachment-id <ID> [--output <path>] For invoices and credit notes, `upload` also accepts `--include-online` to make the attachment visible to the end customer in their online invoice view. Note: the Xero API does not support deleting attachments. ## Architecture All API logic lives in a single shared lib (`src/lib/attachments.ts`) with: - A dispatch map routing each resource type to the correct xero-node SDK method - Pre-flight validation: file-exists check, 25MB size limit, MIME type check - Built-in MIME detection for .pdf, .png, .jpg/.jpeg, .gif, .webp, .xml, .csv, .txt (no new dependencies required) - Download resolves the original filename via a list call before fetching bytes, enabling smart `--output` path handling (file path or directory) Command files are thin wrappers: parse flags → xeroCall → delegate to lib → format output. ## Tests 21 new unit tests in `test/lib/attachments.test.ts` covering MIME detection, file validation, and all three operations across multiple resource types. All 87 tests pass; TypeScript build is clean.
Add bin/bun-run.ts as a Bun-specific entry point that statically imports all command classes so they are bundled into the compiled binary. After loading the oclif Config, each command's lazy loader is patched to return the in-binary class instead of doing a dynamic filesystem import. This fixes the @oclif/core MODULE_NOT_FOUND error that occurs in containers where node_modules is absent but the binary is present alongside dist/. Also adds npm scripts build:binary and build:binary:linux, updates .gitignore to exclude compiled binaries, and includes the updated skills/xero-command-line/SKILL.md with env-var auth bypass docs. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds
attachmentssub-commands to the seven resource types that support file attachments via the Xero Accounting API: invoices, credit-notes, bank-transactions, quotes, contacts, accounts, and manual-journals.Commands added
Each resource gains three new sub-commands following the existing topic/verb pattern:
The same three commands are available for
credit-notes,bank-transactions,quotes,contacts,accounts, andmanual-journalswith their respective ID flags.--include-onlineis available oninvoicesandcredit-notesupload — makes the attachment visible to the end customer in their online invoice/credit note view.Architecture
All API logic lives in a new shared lib
src/lib/attachments.ts:AttachmentResourcetype to the correctxero-nodeSDK method (createInvoiceAttachmentByFileName,getInvoiceAttachments,getInvoiceAttachmentById, etc.).pdf,.png,.jpg/.jpeg,.gif,.webp,.xml,.csv,.txt— no new npm dependencieslistAttachmentscall internally, enabling smart--outputhandling (accepts a file path or directory; defaults to current working directory)Command files are thin wrappers: parse flags →
this.xeroCall→ delegate to lib → format output.Test plan
test/lib/attachments.test.tscovering MIME detection, file validation (not-found, oversized),uploadAttachmentdispatch per resource,listAttachments, anddownloadAttachment(including attachment-not-found error)npm test)npm run build)invoices attachments list,upload, anddownloadall work end-to-end🤖 Generated with Claude Code