@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/AGENTS.md +52 -0
- package/README.md +336 -154
- package/dist/cjs/client.d.ts +135 -6
- package/dist/cjs/client.js +180 -2
- package/dist/cjs/generated.d.ts +113 -4
- package/dist/cjs/generated.js +14 -3
- package/dist/cjs/index.d.ts +1 -1
- package/dist/esm/client.d.ts +135 -6
- package/dist/esm/client.js +179 -2
- package/dist/esm/generated.d.ts +113 -4
- package/dist/esm/generated.js +14 -3
- 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 +223 -8
- package/dist/esm/mcp/reference.js +5 -2
- package/package.json +15 -3
package/README.md
CHANGED
|
@@ -1,106 +1,202 @@
|
|
|
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
|
+
- **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
|
-
|
|
11
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
**
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
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
|
|
35
|
+
**4. Put the key on your server.** Keep it out of your code.
|
|
28
36
|
|
|
29
37
|
```bash
|
|
30
|
-
# .env (not
|
|
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
|
|
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
|
-
|
|
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
|
|
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 },
|
|
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
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
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. |
|
|
127
|
+
Guide: <https://docs.zimmerstack.com/rate-grid>
|
|
128
|
+
|
|
129
|
+
## Set up a hotel's rooms: create, change, delete
|
|
67
130
|
|
|
68
|
-
|
|
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
|
-
|
|
72
|
-
zs.
|
|
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
|
-
|
|
77
|
-
zs.
|
|
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
|
-
|
|
82
|
-
|
|
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
|
-
|
|
85
|
-
zs.
|
|
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
|
-
|
|
88
|
-
zs.
|
|
89
|
-
zs.
|
|
90
|
-
|
|
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
|
-
|
|
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
|
-
|
|
97
|
-
|
|
98
|
-
|
|
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
|
-
|
|
103
|
-
few
|
|
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
|
|
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
|
|
213
|
+
channelPrice(4500, booking.modifier ?? []); // what Booking.com is sent for 4,500. Show it beside your calendar.
|
|
118
214
|
```
|
|
119
215
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
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
|
-
|
|
126
|
-
never from a loop, a timer or a seed script.
|
|
224
|
+
Guide: <https://docs.zimmerstack.com/per-ota>
|
|
127
225
|
|
|
128
|
-
##
|
|
226
|
+
## Many hotels on one key
|
|
129
227
|
|
|
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.
|
|
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
|
|
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
|
-
|
|
141
|
-
|
|
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
|
-
##
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
}
|
|
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
|
|
160
|
-
|
|
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
|
-
|
|
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
|
-
}
|
|
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
|
-
|
|
178
|
-
|
|
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
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
`
|
|
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
|
-
|
|
190
|
-
|
|
191
|
-
|
|
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
|
-
|
|
199
|
-
|
|
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
|
|
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
|
-
|
|
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.
|
|
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
|
-
|
|
216
|
-
|
|
217
|
-
|
|
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
|
|
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
|
|
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
|
-
##
|
|
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
|
-
|
|
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
|
-
|
|
242
|
-
|
|
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
|
-
|
|
401
|
+
**2. A first prompt.** Paste this and change the last line to what you want:
|
|
249
402
|
|
|
250
|
-
|
|
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
|
|
253
|
-
|
|
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
|
|
259
|
-
| `zimmerstack_sandbox_read` | One read on your
|
|
260
|
-
| `zimmerstack_sandbox_write` | One
|
|
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
|
-
|
|
273
|
-
project's `.env.local` or `.env`, so the key never goes into the agent's settings file. It uses
|
|
274
|
-
key only
|
|
275
|
-
|
|
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
|
-
##
|
|
438
|
+
## Words used here
|
|
278
439
|
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
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. |
|