Migrating from v1
v2 is a ground-up rewrite; v1’s hand-written wrapper is gone.
| v1 | v2 |
|---|---|
new Brex(token) |
new Brex({ token }) |
brex.request({ endpoint, method, … }) |
Typed methods, e.g. brex.vendors.list() |
brex.vendors.list() (partial coverage) |
Full coverage of all 10 published APIs |
isomorphic-unfetch polyfill |
Native fetch, zero dependencies |
| CommonJS + ESM | ESM-only (Node ≥ 20.19 require() still works) |
What to change
Section titled “What to change”- Construct with an options object —
new Brex({ token })instead ofnew Brex(token). - Replace raw
request(...)calls with the typed namespace methods. Browse the API reference to find the method that maps to your old endpoint. - Drop the fetch polyfill — v2 uses the runtime’s native
fetch. If you’re on a runtime without one, inject afetchvia the client options. - Expect ESM — the package is ESM-only.
require("brex")still works on Node ≥ 20.19 viarequire(esm).