@zimmerstack/connect 0.4.1 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,106 +1,202 @@
1
1
  # @zimmerstack/connect
2
2
 
3
- The official Node.js client for the [ZimmerStack Connect API](https://docs.zimmerstack.com): read and
4
- set a hotel's availability, prices and stay rules, price each booking site differently, create
5
- bookings, and receive the ones the booking sites send.
3
+ Add a channel manager to your hotel software. This package sends a hotel's rooms and prices to
4
+ Booking.com, Airbnb, Expedia, Agoda, MakeMyTrip and the other booking sites, and brings their bookings
5
+ back to you.
6
6
 
7
- Zero dependencies. Typed from the API's own contract. It keeps the API's rules for you: it paces
8
- itself, retries only what is safe to retry, and never lets a write land twice.
7
+ - **Free to build.** You get a practice hotel the moment you sign up. Nothing you do there reaches a
8
+ real booking site.
9
+ - **One public price.** A fixed price for each live property a month, on one invoice. You accept it in
10
+ the partner portal. No call needed: <https://docs.zimmerstack.com/pricing>
11
+ - **Made for AI coding tools.** The package carries its own rules file and a helper your coding agent
12
+ can ask. See [For AI coding agents](#for-ai-coding-agents).
9
13
 
10
- ```bash
11
- npm install @zimmerstack/connect
12
- ```
14
+ [Docs](https://docs.zimmerstack.com) · [Quickstart](https://docs.zimmerstack.com/quickstart) ·
15
+ [Pricing](https://docs.zimmerstack.com/pricing) · [Partner portal](https://partner.zimmerstack.com/login) ·
16
+ [Starter app](https://github.com/zimmerstack/connect-starter) ·
17
+ [Changelog](https://docs.zimmerstack.com/changelog) · <support@zimmerstack.com>
13
18
 
14
- Node 20 or newer. **Server only**: the key can change a hotel's prices on every channel, so the
15
- package refuses to start in a browser or a mobile app. Your frontend calls your server; your server
16
- calls ZimmerStack. Your app has no server (a Vite, Lovable or Bolt page)? The docs show the smallest
17
- one: <https://docs.zimmerstack.com/sdk#no-server>. Never put the key in a `VITE_` or `NEXT_PUBLIC_`
18
- variable: those are sent to every visitor's browser.
19
+ ## Start in five minutes
19
20
 
20
- ## Start
21
+ **1. Sign up.** It is free and takes one emailed code:
22
+ <https://www.zimmerstack.com/partners/pms-companies#join>. Your practice hotel is made for you. We call
23
+ it a sandbox. Working for one hotel only? Its owner makes your key in Admin → Developers → API keys, and
24
+ you can skip to step 3.
21
25
 
22
- **Get a test key.** A software company: [sign up free](https://www.zimmerstack.com/partners/pms-companies#join)
23
- (your sandbox is made at sign-up), then the [partner portal](https://partner.zimmerstack.com/login) →
24
- Developers → Create key. A hotel's own developer: the owner makes one in Admin → Developers → API keys.
25
- A working app to start from: <https://github.com/zimmerstack/connect-starter>.
26
+ **2. Make a test key.** Open the [partner portal](https://partner.zimmerstack.com/login), then
27
+ Developers, then Create key. A test key starts with `zsk_test_`. It works on your practice hotel only.
28
+
29
+ **3. Install the package.** It needs Node 20 or newer.
30
+
31
+ ```bash
32
+ npm install @zimmerstack/connect
33
+ ```
26
34
 
27
- Put the key in the environment, never in code:
35
+ **4. Put the key on your server.** Keep it out of your code.
28
36
 
29
37
  ```bash
30
- # .env (not committed). zsk_test_… is a sandbox: nothing you send reaches a channel.
38
+ # .env (do not commit this file)
31
39
  ZIMMERSTACK_CONNECT_KEY=zsk_test_…
32
40
  ```
33
41
 
42
+ **5. Make your first call.**
43
+
34
44
  ```ts
35
45
  import { ZimmerStack } from "@zimmerstack/connect";
36
46
 
37
- const zs = new ZimmerStack(); // reads ZIMMERSTACK_CONNECT_KEY; make one per process and reuse it
47
+ const zs = new ZimmerStack(); // reads ZIMMERSTACK_CONNECT_KEY. Make one and reuse it.
48
+
49
+ // Which hotel is this?
50
+ const hotel = await zs.property.get();
51
+ console.log(hotel.name, hotel.currency, hotel.timezone);
52
+
53
+ // The rate calendar for two weeks: rooms down the side, nights across the top.
54
+ const grid = await zs.grid.load("2026-12-01", "2026-12-14");
55
+ console.log(grid.rows.length, "room types");
56
+ ```
57
+
58
+ Want a working app to start from? The [starter app](https://github.com/zimmerstack/connect-starter) has
59
+ a one-click Deploy button.
60
+
61
+ ### The key stays on a server
62
+
63
+ This package runs on a server only. Your key can change a hotel's prices on every booking site, so the
64
+ package refuses to start in a browser or a mobile app. Your web page calls your own server. Your server
65
+ calls ZimmerStack.
66
+
67
+ - Never put the key in a `VITE_`, `NEXT_PUBLIC_`, `REACT_APP_` or `EXPO_PUBLIC_` variable. Those are
68
+ sent to every visitor's browser.
69
+ - Your app has no server (a Vite, Lovable or Bolt page)? The docs show the smallest one:
70
+ <https://docs.zimmerstack.com/sdk#no-server>
71
+
72
+ ## What you can do
38
73
 
39
- // The rate grid for a fortnight: rows are room types with their rate plans, columns are nights.
74
+ | I want to | Call |
75
+ |---|---|
76
+ | See which hotels my key reaches | `zs.properties.list()` |
77
+ | Read one hotel's details | `zs.property.get()` |
78
+ | Show the rate calendar | `zs.grid.load(from, to)` |
79
+ | Save what a person changed in it | `zs.grid.save(edits)` |
80
+ | Set the rooms left to sell | `zs.availability.set(updates)` |
81
+ | Set prices | `zs.rates.set(updates)` |
82
+ | Close a night, or ask for a minimum stay | `zs.restrictions.set(updates)` |
83
+ | List a hotel's room types and rate plans | `zs.roomTypes.list()` · `zs.ratePlans.list()` |
84
+ | Create or change a room type or a rate plan | `zs.roomTypes.save(roomType)` · `zs.ratePlans.save(ratePlan)` |
85
+ | Delete a room type or a rate plan | `zs.roomTypes.delete(idOrRef)` · `zs.ratePlans.delete(idOrRef)` |
86
+ | Charge a different price on one booking site | `zs.channels.setModifier(channelId, steps)` |
87
+ | Read the bookings the booking sites sent | `zs.channelBookings.list()`, or a webhook |
88
+ | Read the bookings made on the hotel's own website | `zs.directBookings.list()` |
89
+ | Pretend a booking came in (practice hotel only) | `zs.sandbox.bookings.create(booking)` |
90
+ | Check that a change reached the booking sites | `zs.batches.wait(batchId)` · `zs.sync.get()` |
91
+ | Create a booking from your own booking engine | `zs.bookings.create(booking)` |
92
+ | Work with many hotels on one key | `zs.forProperty(propertyId)` |
93
+ | Add a hotel | `zs.properties.create(hotel)` |
94
+ | Remove a hotel I added | `zs.properties.delete(propertyId, { confirm })` |
95
+
96
+ Every call and every answer is typed, with the meaning of each field shown in your editor.
97
+
98
+ **Money.** You send a price as a normal number: `4500` means 4,500.00 in the hotel's own currency. When
99
+ you read prices one by one with `zs.rates.get()`, they come back in the smallest unit (`rateMinor`:
100
+ `450000` is 4,500.00). The calendar helpers `zs.grid.load()` and `zs.grid.save()` always use normal
101
+ numbers.
102
+
103
+ **Dates.** A date is a plain calendar day, `YYYY-MM-DD`, on the hotel's own clock.
104
+
105
+ ## Show the rate calendar and save a change
106
+
107
+ ```ts
40
108
  const grid = await zs.grid.load("2026-12-01", "2026-12-14");
41
109
 
42
- // Save what a person changed. Nights are folded into ranges; a large save is split for you.
110
+ // Save only what a person changed. Nights next to each other are sent as one range.
43
111
  const accepted = await zs.grid.save({
44
112
  rates: [
45
- { ratePlanId: 901, date: "2026-12-24", rate: 5200 }, // major units, the hotel's currency: 5200 = 5,200.00
113
+ { ratePlanId: 901, date: "2026-12-24", rate: 5200 },
46
114
  { ratePlanId: 901, date: "2026-12-25", rate: 5200 },
47
115
  ],
48
- restrictions: [{ ratePlanId: 901, date: "2026-12-31", stopSell: true }], // close a night; never a zero price
116
+ restrictions: [{ ratePlanId: 901, date: "2026-12-31", stopSell: true }], // close a night. Never send a price of zero.
49
117
  });
50
118
 
51
- // Accepted means it is in ZimmerStack's record and on its way to the channels.
119
+ // Accepted means ZimmerStack has saved it and is sending it to the booking sites.
52
120
  const batch = await zs.batches.wait(accepted[0]!.batchId); // "landed", or still "pending" after five minutes
53
121
  ```
54
122
 
55
- ## What it does so you do not have to
123
+ Room counts usually reach the booking sites in seconds. A full calendar of prices can take minutes.
124
+ Inside a short-lived function (Vercel, Netlify), show the `batchId` and read `zs.sync.get()` later
125
+ instead of waiting.
56
126
 
57
- | The API's rule | What the client does |
58
- |---|---|
59
- | The key stays on a server | Refuses a browser and React Native. Sends the key to ZimmerStack only. Never prints it: not in errors, not in `console.log(zs)`. |
60
- | Budgets per minute | Reads the `RateLimit` header on every answer and waits before a budget runs out, instead of earning a refusal. |
61
- | Writes are never a burst | Sends writes one at a time, in the order you made them. At most four reads at once. |
62
- | Retry only what passes with time | Retries a used-up budget (429), a fault on ZimmerStack's side (5xx) and a network failure, with a growing wait. Any other refusal is thrown at once, never resent. |
63
- | A retry must not write twice | Gives every write an idempotency key and reuses it on its retries. A write the server keeps no such record for is not resent when its outcome is unknown. |
64
- | A request has a size | Splits a write at 1,000 updates or 5,000 cells. |
65
- | A refused key is not retried | After `API_KEY_INVALID`, `API_KEY_REVOKED` or `API_KEY_EXPIRED` it stops calling. |
66
- | A test must not touch a real hotel | Refuses to write with a `zsk_live_` key under a test runner. |
127
+ Guide: <https://docs.zimmerstack.com/rate-grid>
128
+
129
+ ## Set up a hotel's rooms: create, change, delete
67
130
 
68
- ## Everything it covers
131
+ A **room type** is a kind of room the hotel sells, like "Deluxe Room". A **rate plan** is one way to
132
+ sell it, like "Bed and breakfast". Prices belong to rate plans.
69
133
 
70
134
  ```ts
71
- zs.properties.list() // company keys: the hotels this key may act on
72
- zs.property.get() // timezone, currency, this key's scopes, limits, usage, standing
73
- zs.catalog.get() // room types and rate plans, with the ids every write uses
74
- zs.catalog.upsertRoomTypes(…) / upsertRatePlans(…) / deleteRoomType(id) / deleteRatePlan(id)
135
+ // `ref` is your own id for the room type.
136
+ const room = await zs.roomTypes.save({ ref: "deluxe", name: "Deluxe Room", roomCount: 8, adults: 2 });
75
137
 
76
- zs.availability.get({ from, to }) / .set(updates)
77
- zs.rates.get({ from, to }) / .set(updates) / .resend()
78
- zs.restrictions.get({ from, to }) / .set(updates)
79
- zs.grid.load(from, to) / zs.grid.save(edits)
138
+ // `defaultRate` is the plan's usual price: 4500 means 4,500.00.
139
+ const plan = await zs.ratePlans.save({ ref: "deluxe-bb", roomTypeRef: "deluxe", name: "Bed and breakfast", mealPlan: "CP", defaultRate: 4500 });
80
140
 
81
- zs.sync.get() // how far what you sent has travelled
82
- zs.batches.get(batchId) / .wait(batchId)
141
+ room.id; // name it when you set the rooms left to sell
142
+ plan.id; // name it when you set prices and stay rules
83
143
 
84
- zs.channels.list() // each booking site and the price modifier it holds
85
- zs.channels.setModifier(channelId, steps)
144
+ // Send the same ref again to change it. It never makes a second one.
145
+ await zs.roomTypes.save({ ref: "deluxe", name: "Deluxe Garden Room", roomCount: 8, adults: 2 });
86
146
 
87
- zs.bookings.create(…) / .get(id) / .list(…) / .cancel(id) // your own booking engine
88
- zs.channelBookings.list(…) / .get(id) / .all(…) // what the booking sites sent
89
- zs.directBookings.list(…) / .get(id) / .all(…) // what guests booked on the hotel's own website
90
- zs.directBookings.cancel(id, { refund }) // cancel one from your PMS, with its refund
91
- zs.sandbox.bookings.create(…) / .cancel(id) / .modify(id, …) // pretend an OTA or the website booked (test keys)
147
+ // Delete by your own ref, or by ZimmerStack's id. There is no undo.
148
+ await zs.ratePlans.delete("deluxe-bb");
149
+ await zs.roomTypes.delete("deluxe"); // its rate plans are deleted with it
150
+ ```
92
151
 
93
- zs.request("GET /sync") // any operation of the contract by name, typed
152
+ - These calls need the permission `catalog:write` on the key.
153
+ - To send many at once, use `zs.catalog.upsertRoomTypes(body)` and `zs.catalog.upsertRatePlans(body)`.
154
+ - A delete is refused while a booking site still sells that room or plan. Unmap it on the booking site's
155
+ connection first. Nothing is deleted when a delete is refused.
156
+ - Call a delete only when a person chose to delete that one thing. Never from a loop or a clean-up
157
+ script.
158
+
159
+ Guide: <https://docs.zimmerstack.com/channel-manager>
160
+
161
+ ## Receive bookings
162
+
163
+ A **webhook** is a message ZimmerStack sends to your server when something happens, such as a new
164
+ booking. Add your address in the partner portal under Developers. Then check each message with
165
+ `verifyWebhook` before you trust it.
166
+
167
+ ```ts
168
+ import { isOtaBookingEvent, isWebsiteBookingEvent, verifyWebhook } from "@zimmerstack/connect";
169
+
170
+ export async function POST(request: Request) {
171
+ // Pass the body exactly as it arrived, before any JSON parsing.
172
+ const event = await verifyWebhook(await request.text(), request.headers, process.env.ZIMMERSTACK_WEBHOOK_SECRET!);
173
+ // A message can arrive twice. Remember event.id and skip one you have seen.
174
+ if (isOtaBookingEvent(event)) await save(event.data.booking); // a booking site: created, modified, cancelled
175
+ if (isWebsiteBookingEvent(event)) await applyToMyCalendar(event.data.booking); // the hotel's own website
176
+ return new Response(null, { status: 204 });
177
+ }
94
178
  ```
95
179
 
96
- Every request and answer is typed, with the API's own description on each field. Dates are plain
97
- `YYYY-MM-DD` calendar days in the hotel's timezone. A price is sent in major units and read in minor
98
- units (`rateMinor`); the grid helpers give and take major units.
180
+ `verifyWebhook` throws `ZimmerStackWebhookError` when a message is not from ZimmerStack, or is more than
181
+ five minutes old. Answer 400 and do nothing with the body.
182
+
183
+ Try it on your practice hotel. This pretends Booking.com sent a booking, and your webhook receives the
184
+ real, signed message:
185
+
186
+ ```ts
187
+ await zs.sandbox.bookings.create({ roomTypeId: 412, checkIn: "2026-12-05", nights: 2, rooms: 1, adults: 2, guestName: "Asha Verma", otaName: "Booking.com", paidByOta: false });
188
+ ```
189
+
190
+ No database yet? Read the bookings back any time with `zs.channelBookings.list()`. To catch up after
191
+ your server was down, `zs.channelBookings.all({ since })` gives every booking changed since a time you
192
+ choose.
193
+
194
+ Guide: <https://docs.zimmerstack.com/webhooks>
99
195
 
100
196
  ## A different price on each booking site
101
197
 
102
- One price per rate plan per night goes to every channel. A channel's **modifier** is what differs: a
103
- few ordered steps applied to every price sent to that channel.
198
+ You send one price for each rate plan and night. A booking site's **modifier** changes it for that site
199
+ only: a few steps, applied in order.
104
200
 
105
201
  ```ts
106
202
  import { MODIFIER_TAKES_EFFECT, channelPrice } from "@zimmerstack/connect";
@@ -108,156 +204,218 @@ import { MODIFIER_TAKES_EFFECT, channelPrice } from "@zimmerstack/connect";
108
204
  const { channels } = await zs.channels.list();
109
205
  const booking = channels.find((c) => c.kind === "BookingCom")!;
110
206
 
111
- // Booking.com is sent 18 % more, then 200 less. Needs the scope channel-modifiers:write.
207
+ // Booking.com is sent 18 % more, then 200 less. Needs the permission channel-modifiers:write.
112
208
  await zs.channels.setModifier(booking.channelId, [
113
209
  { action: "increase", type: "percent", value: 18 },
114
210
  { action: "decrease", type: "fixed", value: 200 },
115
211
  ]);
116
212
 
117
- channelPrice(4500, booking.modifier ?? []); // what Booking.com is sent for 4,500: show it beside the grid
213
+ channelPrice(4500, booking.modifier ?? []); // what Booking.com is sent for 4,500. Show it beside your calendar.
118
214
  ```
119
215
 
120
- `MODIFIER_TAKES_EFFECT` is the sentence to show where a person saves one: a modifier applies to
121
- prices sent after the change, and prices already on the channel stay until those nights are sent
122
- again. `zs.rates.resend()` sends them again, unchanged. A hotel may ask a few times a day, so make
123
- it a button of its own and never call it automatically.
216
+ A modifier changes prices sent after you save it. Prices already on the booking site stay until those
217
+ nights are sent again. `MODIFIER_TAKES_EFFECT` is that sentence, ready to show where a person saves.
218
+ `zs.rates.resend()` sends the nights again, unchanged. A hotel may ask a few times a day, so make it a
219
+ button of its own.
220
+
221
+ One call to `zs.channels.setModifier()` moves every price on that booking site. Call it when a person
222
+ saved the setting. Never from a loop, a timer or a set-up script.
124
223
 
125
- One call to `setModifier` moves every price on a channel. Call it when a person saved the setting;
126
- never from a loop, a timer or a seed script.
224
+ Guide: <https://docs.zimmerstack.com/per-ota>
127
225
 
128
- ## A software vendor's company key
226
+ ## Many hotels on one key
129
227
 
130
- A company key reaches many hotels, so every call names one. A **test** company key reaches your
131
- sandboxes; while you have one, the client finds it by itself and the Start example works unchanged.
132
- With several, name one. A live key never guesses.
228
+ A software company's **company key** reaches all its hotels, so each call says which hotel it is for.
133
229
 
134
230
  ```ts
135
231
  const { properties } = await zs.properties.list();
136
- const hotel = zs.forProperty(properties[0]!.id); // the same client and pace, acting on one hotel
232
+ const hotel = zs.forProperty(properties[0]!.id); // the same client, working on one hotel
137
233
  await hotel.grid.load("2026-12-01", "2026-12-14");
138
234
  ```
139
235
 
140
- An app that serves one hotel can name it once instead: `ZIMMERSTACK_PROPERTY_ID=61` in the
141
- environment (or `new ZimmerStack({ propertyId: 61 })`).
236
+ - A **test** company key reaches your practice hotels. While you have only one, the package finds it by
237
+ itself, so the Start example works unchanged. With several, name one.
238
+ - A **live** key never guesses. Always name the hotel.
239
+ - An app that serves one hotel can name it once: `ZIMMERSTACK_PROPERTY_ID=61` on the server, or
240
+ `new ZimmerStack({ propertyId: 61 })`.
142
241
 
143
- ## When the API says no
242
+ ## Add a hotel, remove a hotel
243
+
244
+ A software company can add a hotel and remove one it added from its own code. You need a company key
245
+ with the permission `properties:write`: tick **Also add and remove hotels** when you make the key in the
246
+ partner portal (the account's owner or an Admin can; they are the people who may add a hotel by hand).
247
+ With a test key (`zsk_test_`) the same two calls make and delete a practice hotel, so you can try them
248
+ safely.
144
249
 
145
250
  ```ts
146
- import { ZimmerStackError } from "@zimmerstack/connect";
251
+ // Add a hotel. Its owner gets the sign-in details by email; they are never sent to you.
252
+ const added = await zs.properties.create({
253
+ name: "Ganga Guest House",
254
+ owner: { name: "Meera Joshi", email: "meera@gangaguesthouse.example", phone: "+91 98765 43210" },
255
+ address: { line1: "14 Assi Ghat Road", city: "Varanasi", country: "IN" },
256
+ roomTypes: [{ ref: "rt-river", name: "River View Room", roomCount: 6, defaultRate: 3200 }],
257
+ });
147
258
 
148
- try {
149
- await zs.rates.set(updates);
150
- } catch (err) {
151
- if (!(err instanceof ZimmerStackError)) throw err;
152
- err.code; // stable: "RATE_OUT_OF_BAND", "SCOPE_MISSING", "RATE_LIMITED", … branch on this
153
- err.message; // a sentence for the person in front of the screen: show it
154
- err.retryAfterSeconds; // when a budget refused: when to try again
155
- err.retryable; // false = a verdict on the request. Fix it; never send it again.
156
- }
259
+ // From now on, name the new hotel's id.
260
+ const hotel = zs.forProperty(added.id);
261
+ await hotel.roomTypes.save({ ref: "rt-river", name: "River View Room", roomCount: 6, adults: 2 });
157
262
  ```
158
263
 
159
- The client has already waited and retried where that was worth it. Do not wrap its calls in a retry
160
- loop of your own.
161
-
162
- ## Webhooks
264
+ The hotel works at once and joins your monthly invoice on the next 1st. Its first room types put it on
265
+ the channel manager; then you connect its booking sites in the partner portal.
163
266
 
164
267
  ```ts
165
- import { isOtaBookingEvent, isWebsiteBookingEvent, verifyWebhook } from "@zimmerstack/connect";
166
-
167
- export async function POST(request: Request) {
168
- // The body exactly as it arrived, before any JSON parsing.
169
- const event = await verifyWebhook(await request.text(), request.headers, process.env.ZIMMERSTACK_WEBHOOK_SECRET!);
170
- // Deliveries are at-least-once: remember event.id and skip one you have seen.
171
- if (isOtaBookingEvent(event)) await save(event.data.booking); // channel.booking.created, .modified, .cancelled
172
- if (isWebsiteBookingEvent(event)) await applyToMyCalendar(event.data.booking); // direct.booking.created, .cancelled
173
- return new Response(null, { status: 204 });
174
- }
268
+ // Remove a hotel you added. confirm is the hotel's exact name, so a wrong id never removes a hotel.
269
+ const gone = await zs.properties.delete(added.id, { confirm: added.name });
270
+ gone.channelManager.state; // "REMOVED", or "RETRYING" while one step is still finishing
175
271
  ```
176
272
 
177
- It throws `ZimmerStackWebhookError` for a delivery that is not ZimmerStack's or is older than five
178
- minutes: answer 400 and do not act on the body.
273
+ One call does it all, in this order: the hotel's booking sites are disconnected, its rate plans and
274
+ then its room types are removed from the channel manager, and the hotel is closed. It comes off your
275
+ invoice from the next 1st. **There is no undo.** Call it only when a person chose to remove that
276
+ hotel, never from a loop or a clean-up script. Move the hotel's booking sites to its next channel
277
+ manager first, so it keeps selling.
278
+
279
+ A removal takes a little while, because the booking sites are disconnected one after another. The
280
+ package waits up to a minute and a half for these two calls. If no answer arrives at all (a network
281
+ error), you can safely call `delete` again: a hotel that is already gone answers `replay: true`, and
282
+ one that is still being removed answers `PROPERTY_BUSY` (wait, then ask again).
283
+
284
+ Guide: <https://docs.zimmerstack.com/hotels>
179
285
 
180
286
  ## Bookings from the hotel's own website
181
287
 
182
- A hotel that sells on its own website through ZimmerStack's booking engine, and keeps its own PMS,
183
- gets those bookings in a family of their own: the webhooks `direct.booking.created` and
184
- `direct.booking.cancelled` (the endpoint must list both types; one registered earlier receives none
185
- until its owner ticks them), and `zs.directBookings` for the pull (scope `direct-bookings:read`). The
186
- booking object is the one OTA bookings use. `channel.otaName` is `"Website"`, `finance` is null, and
187
- `amounts.paid` is what the guest paid online. There is no modified event.
288
+ Some hotels sell on their own website through ZimmerStack's booking engine and keep your software as
289
+ their PMS. Those bookings reach you in two ways:
290
+
291
+ - the webhooks `direct.booking.created` and `direct.booking.cancelled` (your address must list both);
292
+ - `zs.directBookings.list()` and `zs.directBookings.all({ since })`, with the permission
293
+ `direct-bookings:read`.
188
294
 
189
- **Apply a website booking to your own calendar before your next push of room counts.** The booking
190
- takes one room off the count the channels hold at once; a push of the old absolute count would put it
191
- back on sale. Read `zs.directBookings.all` before a full push:
295
+ The booking looks like a booking site's booking. `channel.otaName` is `"Website"`, `finance` is null and
296
+ `amounts.paid` is what the guest paid online. There is no "modified" message.
297
+
298
+ **Apply a website booking to your own calendar before you next send room counts.** The booking takes
299
+ one room off the count the booking sites hold. If you then send your old count, that room goes back on
300
+ sale.
192
301
 
193
302
  ```ts
194
303
  for await (const booking of zs.directBookings.all({ since: lastSeen })) applyToMyCalendar(booking);
195
304
  await zs.grid.save(edits); // only now
196
305
  ```
197
306
 
198
- A guest cancels on the booking page, or the hotel cancels in ZimmerStack. From 0.4.0 your PMS can
199
- cancel one too, and say what the guest gets back (scope `direct-bookings:cancel`, granted on its own):
307
+ Your software can also cancel a website booking and say what the guest gets back. This needs its own
308
+ permission, `direct-bookings:cancel`.
200
309
 
201
310
  ```ts
202
311
  const { refund, replay } = await zs.directBookings.cancel(bookingId, { refund: "policy", reason: "Guest phoned to cancel" });
203
- // refund.amount in major units; refund.status NONE, PENDING, PROCESSED or MANUAL
312
+ // refund.amount is a normal number. refund.status is NONE, PENDING, PROCESSED or MANUAL.
313
+ ```
314
+
315
+ - `refund: "policy"` gives back what the booking's own cancellation rules allow now. Use it when the
316
+ guest asked to cancel. It is the default.
317
+ - `refund: "full"` gives back everything the guest paid online. Use it when the hotel is at fault, such
318
+ as an overbooking.
319
+ - `refund: "none"` moves no money. The hotel settles it another way.
320
+
321
+ The refund goes back to the guest's online payment, and is never more than that payment. A booking that
322
+ is checked in, checked out or a no-show answers `BOOKING_NOT_CANCELLABLE`. One that is already cancelled
323
+ answers `replay: true` and moves no money. Your own cancel comes back to you as
324
+ `direct.booking.cancelled`: match it on the booking id and treat it as done. Call this from a person's
325
+ own cancel button, never from a background job.
326
+
327
+ To try it with a test key, call `zs.sandbox.bookings.create({ …, otaName: "Website" })` and then cancel
328
+ that booking. The nights come back and no money moves.
329
+
330
+ Guide: <https://docs.zimmerstack.com/website-bookings>
331
+
332
+ ## When the API says no
333
+
334
+ ```ts
335
+ import { ZimmerStackError } from "@zimmerstack/connect";
336
+
337
+ try {
338
+ await zs.rates.set(updates);
339
+ } catch (err) {
340
+ if (!(err instanceof ZimmerStackError)) throw err;
341
+ err.code; // never changes: "RATE_OUT_OF_BAND", "SCOPE_MISSING", "RATE_LIMITED". Decide on this.
342
+ err.message; // a sentence for the person at the screen. Show it.
343
+ err.retryAfterSeconds; // set when you hit a limit: how long to wait
344
+ err.retryable; // false means the request itself is wrong. Fix it. Do not send it again.
345
+ }
204
346
  ```
205
347
 
206
- `refund` is `"policy"` (the default: what the booking's own cancellation policy gives back now, as if the
207
- guest cancelled on the booking page; for a guest who asks the hotel to cancel), `"full"` (everything
208
- the guest paid online; when the hotel is at fault, such as an overbooking) or `"none"` (the hotel
209
- settles the money another way). The refund goes back to the guest's online payment, never more than
210
- it. A checked-in, checked-out or no-show booking is `BOOKING_NOT_CANCELLABLE`; one already cancelled
211
- answers `replay: true` and moves no money. Your own cancel comes back as `direct.booking.cancelled`
212
- ("Cancelled by the hotel"): match it on the booking id and treat it as already applied. Call it from
213
- a person's own cancel button, never from a sync job.
348
+ The package has already waited and tried again where that could help. Do not put its calls in a retry
349
+ loop of your own.
350
+
351
+ Every code, what it means and what to do: <https://docs.zimmerstack.com/errors>
214
352
 
215
- To try it with a test key, `zs.sandbox.bookings.create({ …, otaName: "Website" })`, then cancel that
216
- booking with `zs.directBookings.cancel`: the nights come back and no money moves.
217
- Guide: <https://docs.zimmerstack.com/website-bookings#cancel>
353
+ ## What the package does for you
354
+
355
+ | The rule | What the package does |
356
+ |---|---|
357
+ | The key stays on a server | Refuses to start in a browser or a mobile app. Sends the key to ZimmerStack only. Never prints it. |
358
+ | You may make only so many calls a minute | Watches the limit and slows down before it is reached. |
359
+ | Changes go out in order | Sends one change at a time, in the order you made them. Reads go up to four at once. |
360
+ | Try again only when that can help | Tries again after a "slow down" answer, a fault on our side or a network failure. Any other "no" comes straight back to you. |
361
+ | A retry must not save twice | Gives each change its own id and reuses it when it tries again, so the same change is never saved twice. A call that cannot be safely repeated, such as a delete, is not sent again when its result is unknown. |
362
+ | A request has a size limit | Splits a save at 1,000 updates or 5,000 night cells. |
363
+ | A refused key is not tried again | After a key is refused, it stops calling. |
364
+ | A test must not touch a real hotel | Refuses to change anything with a `zsk_live_` key while your tests run. |
365
+
366
+ Limits in full: <https://docs.zimmerstack.com/limits>
218
367
 
219
368
  ## Options
220
369
 
221
370
  ```ts
222
371
  new ZimmerStack({
223
372
  apiKey, // default: process.env.ZIMMERSTACK_CONNECT_KEY
224
- propertyId, // company keys: the hotel to act on; default ZIMMERSTACK_PROPERTY_ID (or use forProperty)
225
- timeoutMs: 30_000, // one attempt
226
- maxRetries: 3, // of what may pass later
227
- maxWaitSeconds: 120, // the longest it waits for a budget before giving the refusal back
228
- onEvent: (e) => log(e), // every answer, wait and retry, for your logs; never carries the key
373
+ propertyId, // a company key's hotel. Default: ZIMMERSTACK_PROPERTY_ID (or use forProperty)
374
+ timeoutMs: 30_000, // how long one try may take
375
+ maxRetries: 3, // how many more tries, for what may pass later
376
+ maxWaitSeconds: 120, // the longest it waits for a limit before giving you the "no"
377
+ onEvent: (e) => log(e), // every answer, wait and retry, for your logs. Never carries the key.
229
378
  fetch, // a stand-in for tests
230
379
  });
231
380
  ```
232
381
 
233
- ## Testing your integration
382
+ ## Test your integration
383
+
384
+ Use a `zsk_test_` key, or pass a fake `fetch`. Nothing you do with a test key reaches a booking site,
385
+ and `zs.sandbox.bookings.create()` sends your webhook a real message. A software company makes test keys
386
+ in the partner portal under Developers. A hotel's owner makes one in Admin → Developers → API keys.
234
387
 
235
- Use a `zsk_test_` key (a software company: the partner portal → Developers; a hotel's owner: Admin →
236
- Developers → API keys), or pass a fake `fetch`. Nothing you do with a test key reaches a channel, and `zs.sandbox.bookings.create`
237
- sends your webhook endpoint a real delivery.
388
+ Guide: <https://docs.zimmerstack.com/sandbox>
238
389
 
239
390
  ## For AI coding agents
240
391
 
241
- The package ships its own rules file. Add it to the repository's rules so the agent building on this
242
- package follows it. Append, never copy over: Next.js and other tools write their own `AGENTS.md`.
392
+ Building with Claude Code, Cursor, Codex, Copilot or a tool like Lovable? Give the agent three things.
393
+
394
+ **1. The rules file.** The package ships one. Add it to your project's rules so the agent follows it.
395
+ Add to your file, do not replace it: Next.js and other tools write their own `AGENTS.md`.
243
396
 
244
397
  ```bash
245
398
  cat node_modules/@zimmerstack/connect/AGENTS.md >> AGENTS.md # or >> CLAUDE.md
246
399
  ```
247
400
 
248
- The whole API reference in one file an agent can read: <https://docs.zimmerstack.com/llms-full.txt>.
401
+ **2. A first prompt.** Paste this and change the last line to what you want:
249
402
 
250
- ### An MCP server, so the agent looks things up instead of guessing
403
+ ```text
404
+ Read node_modules/@zimmerstack/connect/AGENTS.md and follow it.
405
+ Use @zimmerstack/connect on the server only, with the key in ZIMMERSTACK_CONNECT_KEY.
406
+ Build a page that shows the rate calendar for the next 14 nights, lets me change a price and save it,
407
+ and add a webhook route that checks each message with verifyWebhook and lists the bookings.
408
+ ```
251
409
 
252
- The package also carries an MCP server. Connect it to your coding agent and the agent can read the
253
- rules, look up any part of the API, and try a call on your sandbox before it writes the code:
410
+ **3. The helper.** The package carries an MCP server. Connect it and the agent can read the rules, look
411
+ up any part of the API, and try a call on your practice hotel before it writes code.
254
412
 
255
413
  | Tool | What the agent gets |
256
414
  |---|---|
257
415
  | `zimmerstack_rules` | The rules for building on the API: the key, pacing, money and dates, a closing checklist. |
258
- | `zimmerstack_reference` | Any operation, type, limit or error code, from the API's own contract. |
259
- | `zimmerstack_sandbox_read` | One read on your sandbox: real ids and real shapes. |
260
- | `zimmerstack_sandbox_write` | One write on your sandbox, to try a body before writing the code that sends it. |
416
+ | `zimmerstack_reference` | Any call, type, limit or error code, from the API's own contract. |
417
+ | `zimmerstack_sandbox_read` | One read on your practice hotel: real ids and real shapes. |
418
+ | `zimmerstack_sandbox_write` | One change on your practice hotel, to try a request before writing the code that sends it. |
261
419
 
262
420
  ```bash
263
421
  # Claude Code
@@ -269,15 +427,39 @@ claude mcp add zimmerstack -- npx -y @zimmerstack/connect mcp
269
427
  { "mcpServers": { "zimmerstack": { "command": "npx", "args": ["-y", "@zimmerstack/connect", "mcp"] } } }
270
428
  ```
271
429
 
272
- It runs on your own machine. It reads `ZIMMERSTACK_CONNECT_KEY` from the environment, or from your
273
- project's `.env.local` or `.env`, so the key never goes into the agent's settings file. It uses the
274
- key only when it is a sandbox key (`zsk_test_…`) and refuses a live one: an agent cannot change a
275
- real hotel through it. Without a key the rules and the reference still work.
430
+ The helper runs on your own machine. It reads `ZIMMERSTACK_CONNECT_KEY` from the environment, or from
431
+ your project's `.env.local` or `.env`, so the key never goes into the agent's settings file. It uses a
432
+ test key only and refuses a live one, so an agent cannot change a real hotel through it. Without a key,
433
+ the rules and the lookups still work.
434
+
435
+ The whole API in one file an agent can read: <https://docs.zimmerstack.com/llms-full.txt>.
436
+ More: <https://docs.zimmerstack.com/ai>
276
437
 
277
- ## Links
438
+ ## Words used here
278
439
 
279
- - Guides and reference: <https://docs.zimmerstack.com>
280
- - Build a rate grid: <https://docs.zimmerstack.com/rate-grid>
281
- - Prices per channel: <https://docs.zimmerstack.com/per-ota>
282
- - Bookings from the hotel's own website: <https://docs.zimmerstack.com/website-bookings>
283
- - Limits: <https://docs.zimmerstack.com/limits> · Errors: <https://docs.zimmerstack.com/errors>
440
+ | Word | What it means |
441
+ |---|---|
442
+ | Booking site | A website that sells the hotel's rooms: Booking.com, Airbnb, Expedia and the rest. Travel people say OTA. The API calls each one a channel. |
443
+ | Sandbox | Your practice hotel. It behaves like a real one, but no booking site ever sees it. |
444
+ | Key | A password for your software. `zsk_test_` works on a sandbox, `zsk_live_` on a real hotel. |
445
+ | Company key | One key for all of a software company's hotels. Each call says which hotel it is for. |
446
+ | Room type | A kind of room the hotel sells, like "Deluxe Room". |
447
+ | Rate plan | One way to sell a room type, like "Bed and breakfast". Prices belong to rate plans. |
448
+ | Stay rule | A rule for a night: closed for sale, or a minimum number of nights. The API calls these restrictions. |
449
+ | Webhook | A message ZimmerStack sends to your server when something happens, such as a new booking. |
450
+ | Permission | What a key may do, like `catalog:write` for changing room types and rate plans. The API calls it a scope. |
451
+
452
+ More words: <https://docs.zimmerstack.com/glossary>
453
+
454
+ ## Find everything
455
+
456
+ | Where | What is there |
457
+ |---|---|
458
+ | <https://docs.zimmerstack.com> | The guides and the full reference |
459
+ | <https://docs.zimmerstack.com/quickstart> | The first calls, step by step |
460
+ | <https://docs.zimmerstack.com/pricing> | What a live property costs a month |
461
+ | <https://www.zimmerstack.com/partners/pms-companies#join> | Sign up, free |
462
+ | <https://partner.zimmerstack.com/login> | The partner portal: your practice hotels, keys, webhooks, hotels and bills |
463
+ | <https://github.com/zimmerstack/connect-starter> | A working app to start from, with a Deploy button |
464
+ | <https://docs.zimmerstack.com/changelog> | What changed, and when |
465
+ | <support@zimmerstack.com> | Questions, from any time zone. Answered within one working day. |