Skip to content
Thelost77Public

About

Independent, unofficial Go CLI wrapper for the inFakt API v3, designed for AI agents

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

8 Commits

Folders and files

Repository files navigation

buk

buk is an independent, unofficial Go CLI wrapper for the inFakt API v3. It is designed for shell-capable AI agents that need to discover the API contract before executing an operation.

Important

buk is not affiliated with, endorsed by, sponsored by, or maintained by inFakt. The inFakt name and related marks belong to their respective owners and are used here only to identify the service and API with which buk interoperates.

The embedded catalog covers all 203 request entries published by docs.infakt.pl: 193 active entries and 10 deprecated entries. A consolidated reference is available in docs/infakt-api-v3.md.

Features

  • Offline discovery of operation groups and all API contracts
  • Stable JSON output for agent automation
  • JSON and multipart request bodies
  • JSON, PDF, XML, HTML, and ZIP responses
  • Explicit polling for documented asynchronous operations
  • Structured API errors and stable exit codes
  • Sandbox-first execution with explicit production selection
  • Exact confirmation for writes, deletes, external actions, and side-effectful reads
  • Complete source provenance and reproducible documentation generation
  • Zero external Go runtime dependencies

Safety model

  • Sandbox is the default environment.
  • Production requires the explicit flag --environment production on every call.
  • The API key is read only from INFAKT_API_KEY.
  • Every operation whose risk is not read requires --confirm OPERATION_ID.
  • Deprecated operations cannot be executed.
  • Unverified supplemental operations require --allow-unverified.
  • --dry-run does not require a key and never sends a request.
  • The HTTP client rejects arbitrary hosts, relative paths, and redirects.
  • Mutating requests are not retried automatically.
  • Binary responses require an explicit output destination.

These controls reduce accidental execution. They do not replace user approval or professional accounting review.

Requirements

  • Go 1.25 or newer.
  • An inFakt API key with scopes required by the selected operation.

Installation

From the repository:

go build -o buk ./cmd/buk

Install from GitHub:

go install github.com/Thelost77/buk/cmd/buk@latest

Authentication

Set the key in the process environment. Do not place it in command arguments, examples, prompts, or committed files.

export INFAKT_API_KEY='...'

INFAKT_ENV may set the default environment to sandbox or production. A production call still requires --environment production explicitly.

Help and discovery

Every command level supports -h and --help. Help can also be addressed by topic:

buk --help
buk help operations
buk help operations list
buk help operations describe
buk help call
buk --version

Help and operation discovery work offline and do not require an API key.

Agent workflow

1. Discover groups and operations

buk operations groups
buk operations list --group przychody.faktury-vat

Filter by risk or documentation status:

buk operations list --risk read
buk operations list --status unverified
buk operations list --include-deprecated

2. Inspect the exact contract

buk operations describe przychody.faktury-vat.stworz

The result includes the method, normalized path, required scopes, body mode, source description, examples, response mode, risk, and asynchronous completion metadata.

3. Preview the request

buk call przychody.faktury-vat.stworz \
  --input examples/invoice-create.json \
  --wait \
  --dry-run

4. Execute after approval

buk call przychody.faktury-vat.stworz \
  --input examples/invoice-create.json \
  --wait \
  --confirm przychody.faktury-vat.stworz

The example contains placeholder client data. Replace it with an ID returned by the current account before execution.

Calling operations

Path parameters

buk call przychody.faktury-vat.pokaz-szczegoly \
  --path invoice_uuid=INVOICE_UUID

Query parameters and filters

buk call przychody.faktury-vat.listuj \
  --query limit=25 \
  --query offset=0 \
  --query 'q[paid_date_null]=true' \
  --query 'order=invoice_date desc'

Repeated query keys are preserved.

JSON input

buk call przychody.klienci.stworz \
  --input examples/client-create.json \
  --confirm przychody.klienci.stworz

Use --input - to read one JSON document from standard input.

Multipart input

See examples/cost-upload.md.

Binary output

Known PDF, XML, ZIP, and HTML download operations require --output:

buk call przychody.faktury-vat.pobierz-pdf \
  --path invoice_uuid=INVOICE_UUID \
  --output invoice.pdf \
  --confirm przychody.faktury-vat.pobierz-pdf

Files are created with mode 0600. Use --output - only when the caller expects binary standard output.

Asynchronous operations

For operations with embedded async metadata, --wait polls until a documented terminal state:

buk call przychody.faktury-vat.stworz \
  --input examples/invoice-create.json \
  --confirm przychody.faktury-vat.stworz \
  --wait \
  --poll-interval 2s \
  --timeout 2m

The poller fails closed on unknown states. It does not infer success.

Money and identifiers

  • Documented monetary values use integer minor units. 100000 means 1000.00 PLN.
  • Do not convert money through float64.
  • Invoices normally use UUID values in paths.
  • Clients, products, bank accounts, and some accounting resources use numeric IDs.
  • KSeF operations distinguish document UUID, request UUID, task reference, and KSeF number.

Always inspect the operation before selecting an identifier.

Output contract

  • Successful non-empty JSON responses are written to stdout without an envelope.
  • --pretty indents valid JSON responses.
  • A successful non-read operation with an empty response writes JSON containing status, operation_id, and ok: true.
  • A successful read with an empty response produces empty stdout.
  • A downloaded file produces JSON metadata unless --output - is used.
  • Errors are written as JSON to stderr and leave stdout empty.

Exit codes:

  • 0: success
  • 1: transport or internal failure
  • 2: usage, configuration, confirmation, deprecated, or unverified operation
  • 3: authorization failure
  • 4: resource not found
  • 5: validation, plan, lock, or asynchronous failure
  • 6: rate limit, unavailable service, server failure, or timeout

Production calls

A production read requires an explicit environment flag:

buk call przychody.faktury-vat.listuj \
  --environment production

A production write requires both the environment and exact operation confirmation:

buk call przychody.faktury-vat.stworz \
  --environment production \
  --input invoice.json \
  --confirm przychody.faktury-vat.stworz

Documentation

The live Postman collection is the primary source. GitHub-only operations are supplemental and marked unverified.

Regenerate the catalog and reference from the current public sources:

python3 tools/generate_docs.py

Review source hashes and catalog test failures before accepting an upstream documentation change.

Testing

go test ./...
go test -race ./...
go vet ./...
go build ./cmd/buk

Optional read-only sandbox contract tests:

INFAKT_API_KEY='...' go test -tags=integration ./integration -run TestSandboxReadOnly

Optional sandbox mutation test:

INFAKT_API_KEY='...' \
INFAKT_SANDBOX_WRITE_TESTS=1 \
go test -tags=integration ./integration -run TestSandboxClientLifecycle

The integration suite uses the hard-coded sandbox base URL and never mutates production.

Releases

Releases use SemVer tags with a leading v. Keep reviewed release notes in docs/releases/ and publish the tag and GitHub Release together:

${EDITOR:-vi} docs/releases/v0.1.0.md
./scripts/release.sh v0.1.0

Install a specific release:

go install github.com/Thelost77/buk/cmd/buk@v0.1.0

Architecture

cmd/buk/          process entry point
internal/api/        safe authenticated HTTP transport and API errors
internal/catalog/    embedded normalized operation catalog
internal/cli/        help, discovery, input handling, execution, and polling
integration/         opt-in sandbox contract tests
tools/               documentation fetch and generation
docs/                API reference, source provenance, agent policy, and plans
examples/            reviewed request and workflow examples

Status

The catalog, offline discovery, request execution, safety gates, multipart and binary handling, and asynchronous polling are implemented and covered by unit tests. Authenticated endpoint contracts remain documented-unverified until they pass controlled sandbox tests.

Known limits

  • Public documentation does not define every error body.
  • The normal sandbox may not expose cost and accounting workflows.
  • supplemental.ksef2.cancel-export is absent from Postman and remains unverified.
  • The CLI executes API operations. It does not determine whether an accounting or tax action is legally correct.

Trademark and affiliation

buk is an independent open-source project. It is not an official inFakt implementation and has no affiliation with inFakt. No inFakt trademark, logo, or brand asset is licensed to this project. References to inFakt are descriptive and identify API compatibility only.

License

MIT. The MIT license covers this project's code and documentation; it does not grant rights to third-party names or marks.

About

Independent, unofficial Go CLI wrapper for the inFakt API v3, designed for AI agents

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages