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