@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/AGENTS.md +63 -5
- package/README.md +356 -154
- package/dist/cjs/client.d.ts +139 -10
- package/dist/cjs/client.js +184 -6
- package/dist/cjs/generated.d.ts +115 -6
- package/dist/cjs/generated.js +15 -4
- package/dist/cjs/index.d.ts +1 -1
- package/dist/cjs/webhooks.d.ts +21 -11
- package/dist/cjs/webhooks.js +13 -6
- package/dist/esm/client.d.ts +139 -10
- package/dist/esm/client.js +183 -6
- package/dist/esm/generated.d.ts +115 -6
- package/dist/esm/generated.js +15 -4
- package/dist/esm/index.d.ts +1 -1
- package/dist/esm/mcp/reference.generated.d.ts +2 -0
- package/dist/esm/mcp/reference.generated.js +231 -16
- package/dist/esm/mcp/reference.js +5 -2
- package/dist/esm/webhooks.d.ts +21 -11
- package/dist/esm/webhooks.js +13 -6
- package/package.json +20 -3
package/README.md
CHANGED
|
@@ -1,106 +1,205 @@
|
|
|
1
1
|
# @zimmerstack/connect
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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
|
-
|
|
8
|
-
|
|
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
|
-
|
|
11
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
**
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
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
|
|
38
|
+
**4. Put the key on your server.** Keep it out of your code.
|
|
28
39
|
|
|
29
40
|
```bash
|
|
30
|
-
# .env (not
|
|
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
|
|
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
|
-
|
|
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
|
|
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 },
|
|
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
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
58
|
-
|
|
59
|
-
|
|
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
|
-
|
|
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
|
-
|
|
72
|
-
zs.
|
|
73
|
-
|
|
74
|
-
|
|
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
|
-
|
|
77
|
-
|
|
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
|
-
|
|
82
|
-
zs.
|
|
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
|
-
|
|
85
|
-
zs.
|
|
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
|
-
|
|
88
|
-
|
|
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
|
-
|
|
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
|
-
|
|
97
|
-
|
|
98
|
-
|
|
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
|
-
|
|
103
|
-
few
|
|
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
|
|
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
|
|
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:
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
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
|
-
|
|
126
|
-
never from a loop, a timer or a seed script.
|
|
228
|
+
Guide: <https://docs.zimmerstack.com/per-ota>
|
|
127
229
|
|
|
128
|
-
##
|
|
230
|
+
## Many hotels on one key
|
|
129
231
|
|
|
130
|
-
A company key reaches
|
|
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
|
|
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
|
-
|
|
141
|
-
|
|
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
|
-
##
|
|
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
|
-
|
|
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
|
-
|
|
149
|
-
|
|
150
|
-
|
|
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
|
|
160
|
-
|
|
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
|
-
|
|
166
|
-
|
|
167
|
-
|
|
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
|
-
|
|
178
|
-
|
|
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
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
`
|
|
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
|
|
190
|
-
|
|
191
|
-
|
|
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
|
-
|
|
199
|
-
|
|
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
|
|
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
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
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
|
-
|
|
216
|
-
|
|
217
|
-
|
|
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
|
|
225
|
-
timeoutMs: 30_000, // one
|
|
226
|
-
maxRetries: 3, //
|
|
227
|
-
maxWaitSeconds: 120, // the longest it waits for a
|
|
228
|
-
onEvent: (e) => log(e), // every answer, wait and retry, for your logs
|
|
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
|
-
##
|
|
401
|
+
## Test your integration
|
|
234
402
|
|
|
235
|
-
Use a `zsk_test_` key
|
|
236
|
-
|
|
237
|
-
|
|
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
|
-
|
|
242
|
-
|
|
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
|
-
|
|
420
|
+
**2. A first prompt.** Paste this and change the last line to what you want:
|
|
249
421
|
|
|
250
|
-
|
|
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
|
|
253
|
-
|
|
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
|
|
259
|
-
| `zimmerstack_sandbox_read` | One read on your
|
|
260
|
-
| `zimmerstack_sandbox_write` | One
|
|
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
|
-
|
|
273
|
-
project's `.env.local` or `.env`, so the key never goes into the agent's settings file. It uses
|
|
274
|
-
key only
|
|
275
|
-
|
|
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
|
-
|
|
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
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
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. |
|