fairnight-beds24
v0.2.1
Published
Beds24 connector for Fairnight: read rooms and bookings, write nightly prices and minimum stays through the official API v2 (refresh token, credit-aware).
Maintainers
Readme
fairnight-beds24
The Beds24 connector of Fairnight. Hosts use it through the fairnight beds24 commands of fairnight-cli. This package is the library underneath.
Built only from Beds24's public documentation: the API V2.0 wiki and the OpenAPI spec at beds24.com/api/v2. No scraping, and no dependencies besides the Fairnight engine's types. It uses Node's own fetch.
What it does
- Authenticates.
- It turns an invite code into a refresh token (
GET /authentication/setup). - It gets short tokens from it (
GET /authentication/token), with the lifetime fromexpiresIn. - It renews them when less than 2 minutes are left, and once, at once, after a 401 in the middle of a run.
- It can reuse a token saved by a previous run.
- It turns an invite code into a refresh token (
- Watches the credits:
- it reads
X-FiveMinCreditLimit,-Remaining,-ResetsInandX-RequestCost(also in the wiki'sx-five-min-limit-*spelling); - it never uses more than half of the 5-minute window;
- on 429 it waits for the window to reset, plus one second;
- 5xx are retried after 1, 2, 4 and 8 seconds;
- 400 and the rest stop with Beds24's message.
- it reads
- Reads rooms (
GET /properties?includeAllRooms=true), bookings (GET /bookings, every page) and the calendar (GET /inventory/rooms/calendar, expanded night by night). - Writes (
POST /inventory/rooms/calendar) only the chosen price field andminStay, one element per write. It reports the answer of each element. - Plans a push (
planPush,buildWrites) and maps bookings (mapBookings):- confirmed, new and request are bookings;
- black is blocked;
- cancelled is removed;
- inquiry is ignored.
No token ever appears in an error message.
Tests
Every test runs against a fake Beds24 server on 127.0.0.1. It follows the spec's shapes and reproduces:
- tokens that expire;
- credits that run out (429 with
ResetsIn); - paginated bookings;
- calendar runs;
- 201 answers with errors for some elements.
No test ever calls the real Beds24.
License
AGPL-3.0-only. See LICENSE.
