Files
actual/packages/api/models.ts
Matiss Janis Aboltins 168fe0d68b [AI] Add api.importBudget() and api.exportBudget() (#8414)
* [AI] Add api.importBudget() and api.exportBudget()

Add first-class import/export functions to @actual-app/api so consumers
no longer have to drive the low-level worker RPC and the engine
filesystem by hand.

- api.importBudget(pathOrBytes, { type?, filename? }) imports an Actual
  .zip export (or a YNAB4/YNAB5 export), loads it, and resolves with the
  imported budget id. Raw bytes are passed straight to the import-budget
  handler instead of the upload-file-web temp-file dance, so it works in
  both the Node and browser builds and leaves no temp files behind.
- api.exportBudget() exports the currently-loaded budget and resolves
  with the zip contents as a Uint8Array.
- Both reject with an Error on failure instead of resolving { error }.
- The import-budget handler now optionally accepts raw file contents
  (buffer + filename) alongside the existing filepath input, and returns
  the id of the loaded budget on success; existing callers are
  unaffected.
- Add round-trip, file-path, and failure integration tests; update the
  API reference docs.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014wq2oMcHb99mLb9qpaR8SN

* [AI] Move ImportableBudgetType re-export to models.ts

Type re-exports for API consumers live in models.ts (like Preferences),
not methods.ts — follow the existing pattern.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014wq2oMcHb99mLb9qpaR8SN

* [AI] Address review: relax error assertions, document type union

- Assert importBudget failures on the stable "Error importing budget:"
  prefix instead of backend-specific error codes
- Document options.type as the 'actual' | 'ynab4' | 'ynab5' union in the
  API reference instead of a generic string

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014wq2oMcHb99mLb9qpaR8SN

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-07-06 17:42:45 +00:00

4 lines
222 B
TypeScript

export type * from '@actual-app/core/server/api-models';
export type { ImportableBudgetType } from '@actual-app/core/server/importers/index';
export type { SyncedPrefs as Preferences } from '@actual-app/core/types/prefs';