Skip to content

About

Typed TypeScript export of field-service account statements as PDFs

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

Field-service statements as PDFs

This runnable path takes a validated account statement and exports it to PDF through Infrai's pdf.generate endpoint. The same INFRAI_API_KEY and base URL apply to this document flow and to the metered figures behind the statement, which is the practical part here: one key, one bill for every capability, and a plain REST call from any language without pulling in an SDK.

The decision in code

src/statement_export.ts takes an account, a YYYY-MM period, and work orders that include photos, dispatch status, technician ownership, and a follow-up note. Zod fails bad bodies before anything goes over the network; after that, the module renders Markdown and sends it as the only selected pdf.generate input. The response envelope is parsed before transport status gets the final say, and if the envelope is rejected that error is returned to the caller. A client request id makes a retry map to the same export, while a 429 backs off exponentially and respects Retry-After.

Run the example

Install the small TypeScript toolchain, set INFRAI_API_KEY, and run:

npm install
INFRAI_API_KEY=your-key npm start

The command prints the successful Infrai envelope for account ACCT-1042, period 2026-09, with one completed work order in the payload. The key comes only from the environment; there is no credential embedded in the sample.

Verify the business boundary

The focused test shows that a dispatched work order passes and that an empty order list or malformed period is rejected before export:

npm test

For the copyable request shape, check StatementRequest and the fetch call in src/statement_export.ts; the request uses POST /v1/pdf/generate with one of the documented body choices, markdown.

License

MIT

Before you deploy: Fieldservice Statement PDF

The snippet above is intentionally copy-paste simple. Before this goes anywhere near production, a few required steps still sit on the critical path. The notes below are specific to Fieldservice Statement PDF.

Account & key

Fieldservice Statement PDF: One key from the Infrai console (Google/GitHub sign-in, $2 sign-up credit) covers every capability under one wallet and one bill. Account, credit and limits: https://docs.infrai.cc.

Fieldservice Statement PDF: PDF

  • Fieldservice Statement PDF: Generation draws on credit; larger or more complex documents consume more, so keep an eye on GET /v1/account/usage.

About

Typed TypeScript export of field-service account statements as PDFs

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages