@zimmerstack/connect 0.0.0-stage → 0.1.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 +99 -0
- package/LICENSE +21 -0
- package/README.md +225 -2
- package/dist/cjs/client.d.ts +260 -0
- package/dist/cjs/client.js +562 -0
- package/dist/cjs/errors.d.ts +46 -0
- package/dist/cjs/errors.js +51 -0
- package/dist/cjs/generated.d.ts +1153 -0
- package/dist/cjs/generated.js +135 -0
- package/dist/cjs/grid.d.ts +105 -0
- package/dist/cjs/grid.js +135 -0
- package/dist/cjs/index.d.ts +16 -0
- package/dist/cjs/index.js +30 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/webhooks.d.ts +60 -0
- package/dist/cjs/webhooks.js +103 -0
- package/dist/esm/client.d.ts +260 -0
- package/dist/esm/client.js +558 -0
- package/dist/esm/errors.d.ts +46 -0
- package/dist/esm/errors.js +46 -0
- package/dist/esm/generated.d.ts +1153 -0
- package/dist/esm/generated.js +132 -0
- package/dist/esm/grid.d.ts +105 -0
- package/dist/esm/grid.js +127 -0
- package/dist/esm/index.d.ts +16 -0
- package/dist/esm/index.js +11 -0
- package/dist/esm/mcp/cli.d.ts +2 -0
- package/dist/esm/mcp/cli.js +86 -0
- package/dist/esm/mcp/key.d.ts +9 -0
- package/dist/esm/mcp/key.js +31 -0
- package/dist/esm/mcp/reference.d.ts +11 -0
- package/dist/esm/mcp/reference.generated.d.ts +33 -0
- package/dist/esm/mcp/reference.generated.js +2084 -0
- package/dist/esm/mcp/reference.js +137 -0
- package/dist/esm/mcp/server.d.ts +29 -0
- package/dist/esm/mcp/server.js +223 -0
- package/dist/esm/webhooks.d.ts +60 -0
- package/dist/esm/webhooks.js +98 -0
- package/package.json +61 -4
package/AGENTS.md
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
# Building on @zimmerstack/connect: rules for coding agents
|
|
2
|
+
|
|
3
|
+
You are writing code that calls the ZimmerStack Connect API through its official package. A write
|
|
4
|
+
through it changes a real hotel's prices and rooms on every booking site it sells on. The package
|
|
5
|
+
enforces most of the API's rules for you; this file is the rest. Keep it in the repository (as
|
|
6
|
+
AGENTS.md or CLAUDE.md) and follow it. The whole API reference, in one file an agent can read:
|
|
7
|
+
https://docs.zimmerstack.com/llms-full.txt
|
|
8
|
+
|
|
9
|
+
## The key
|
|
10
|
+
|
|
11
|
+
- It lives in the environment variable `ZIMMERSTACK_CONNECT_KEY` on a server. Never write it into a
|
|
12
|
+
file that is committed, a log line, an error message, a URL, a test fixture or anything a browser
|
|
13
|
+
or a mobile app receives. Never print it. `new ZimmerStack()` reads it by itself.
|
|
14
|
+
- The package refuses to start in a browser or in React Native. Do not work around that: the
|
|
15
|
+
person's own frontend calls their own server, and the server calls ZimmerStack.
|
|
16
|
+
- `zsk_test_…` is a sandbox: nothing reaches a channel. Build and test with it. `zsk_live_…` is a real
|
|
17
|
+
hotel. The package refuses to WRITE with a live key under a test runner; never switch that off to
|
|
18
|
+
make a test pass.
|
|
19
|
+
- A software vendor's company key acts on one hotel at a time: `zs.forProperty(propertyId)`
|
|
20
|
+
(`zs.properties.list()` names them).
|
|
21
|
+
|
|
22
|
+
## Let the package pace; never work around it
|
|
23
|
+
|
|
24
|
+
- It reads the `RateLimit` header and slows down before a budget runs out, sends writes one at a
|
|
25
|
+
time, retries only what passes with time (429, 5xx, a network failure) under the same idempotency
|
|
26
|
+
key, and gives up with a `ZimmerStackError` otherwise. Do not wrap its calls in your own retry
|
|
27
|
+
loop, and never resend a 4xx other than 429: it is a verdict on the request. Fix the request.
|
|
28
|
+
- Per minute: 120 requests and 30 writes per key; 300 and 60 for all of a hotel's keys together.
|
|
29
|
+
A hotel also has budgets per hour and per day that count CHANGED cells (at least 10,000 an hour, 30,000
|
|
30
|
+
a day). Hitting one is `error.code === "RATE_LIMITED"` with `error.retryAfterSeconds`: tell the
|
|
31
|
+
person when to try again; do not sleep through an hour.
|
|
32
|
+
- One instance per process (`new ZimmerStack()` once, in a module). Two instances do not share a pace.
|
|
33
|
+
- Never write on a timer, in a loop over all nights, or "to be safe". Send what a person changed,
|
|
34
|
+
when they changed it: `zs.grid.save(edits)` folds nights into ranges and splits a large save.
|
|
35
|
+
- Do not poll faster than every 15 seconds (`zs.batches.wait` already does it right), and stop.
|
|
36
|
+
|
|
37
|
+
## Money and dates
|
|
38
|
+
|
|
39
|
+
- A price is SENT in major units (4500 = ₹4,500.00) with the hotel's own currency, and READ in minor
|
|
40
|
+
units (`rateMinor`). `zs.grid.load` gives major units; `zs.grid.save` takes them.
|
|
41
|
+
- A date is a plain `YYYY-MM-DD` calendar day in the hotel's timezone. Never build one with
|
|
42
|
+
`new Date()` arithmetic in local time; use `eachDate(from, to)`.
|
|
43
|
+
- To close a night send `stopSell: true`. Never a zero price, never zero rooms as a substitute.
|
|
44
|
+
- Writes may reach 365 days ahead. A write is accepted (202) when it is in ZimmerStack's record; it
|
|
45
|
+
reaches the channels in seconds to minutes. `zs.sync.get()` says how far along it is.
|
|
46
|
+
|
|
47
|
+
## A channel's price modifier
|
|
48
|
+
|
|
49
|
+
- `zs.channels.setModifier(channelId, steps)` moves EVERY price sent to that channel from then on.
|
|
50
|
+
Call it only when a person saved that setting on a screen. Never from a loop, a timer, a seed
|
|
51
|
+
script or a test against a live key. A hotel may change modifiers 6 times a day.
|
|
52
|
+
- A modifier applies to prices sent to the channel after the change. Prices already on the channel stay as they are until those nights are sent again.
|
|
53
|
+
Show that sentence where the person saves (`MODIFIER_TAKES_EFFECT`), and offer
|
|
54
|
+
`zs.rates.resend()` as a separate, deliberate button ("Apply to nights already on sale"): 3 a day
|
|
55
|
+
per hotel, never automatic.
|
|
56
|
+
- Keep the grid on the price before any modifier; show a channel's price beside it with
|
|
57
|
+
`channelPrice(rate, steps)`.
|
|
58
|
+
|
|
59
|
+
## Errors
|
|
60
|
+
|
|
61
|
+
```ts
|
|
62
|
+
import { ZimmerStack, ZimmerStackError } from "@zimmerstack/connect";
|
|
63
|
+
|
|
64
|
+
try {
|
|
65
|
+
await zs.rates.set(updates);
|
|
66
|
+
} catch (err) {
|
|
67
|
+
if (err instanceof ZimmerStackError) {
|
|
68
|
+
// err.code is stable (RATE_LIMITED, RATE_OUT_OF_BAND, SCOPE_MISSING, …); err.message is for people.
|
|
69
|
+
// Show err.message to the person; branch on err.code; never retry unless err.retryable.
|
|
70
|
+
}
|
|
71
|
+
throw err;
|
|
72
|
+
}
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
- `SCOPE_MISSING`: the key was not given that permission. Say which one is missing; the hotel's
|
|
76
|
+
owner grants it (Admin → Developers → API keys). Do not look for another route.
|
|
77
|
+
- `API_KEY_INVALID`, `API_KEY_REVOKED`, `API_KEY_EXPIRED`: stop. The client refuses every later call
|
|
78
|
+
by itself; repeated bad calls get the server's address refused.
|
|
79
|
+
- `RATE_OUT_OF_BAND`, `MODIFIER_OUT_OF_BAND`: the value is outside what the hotel allows. It is a
|
|
80
|
+
guard against a typing slip; show the message, never split the change into smaller steps to pass.
|
|
81
|
+
|
|
82
|
+
## The MCP server
|
|
83
|
+
|
|
84
|
+
The package carries an MCP server for you, the agent: `npx -y @zimmerstack/connect mcp`. If it is
|
|
85
|
+
connected, use it instead of guessing: `zimmerstack_reference` looks up any operation, type, limit
|
|
86
|
+
or error code from the API's own contract, and `zimmerstack_sandbox_read` /
|
|
87
|
+
`zimmerstack_sandbox_write` make one call on the sandbox so you can see real ids and try a body
|
|
88
|
+
before you write the code that sends it. It works with a `zsk_test_` key only and refuses a live
|
|
89
|
+
one. It is for building; the application you write calls the API through the client, never through
|
|
90
|
+
these tools.
|
|
91
|
+
|
|
92
|
+
## Before you call the work done
|
|
93
|
+
|
|
94
|
+
- [ ] The key is read from the environment, on a server, and appears in no committed file or log.
|
|
95
|
+
- [ ] Every screen that writes sends only what the person changed, once, on their action.
|
|
96
|
+
- [ ] No retry loop, no timer and no polling faster than 15 seconds around a call of this package.
|
|
97
|
+
- [ ] Errors show `err.message` to the person and branch on `err.code`.
|
|
98
|
+
- [ ] Tests run against a `zsk_test_` key or a fake `fetch`; none needs a live key.
|
|
99
|
+
- [ ] Where a modifier is saved, the screen says when it takes effect, and the re-send is its own button.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 ZimmerStack
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,226 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @zimmerstack/connect
|
|
2
2
|
|
|
3
|
-
|
|
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.
|
|
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.
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
npm install @zimmerstack/connect
|
|
12
|
+
```
|
|
13
|
+
|
|
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.
|
|
17
|
+
|
|
18
|
+
## Start
|
|
19
|
+
|
|
20
|
+
Put the key in the environment, never in code:
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
# .env (not committed). zsk_test_… is a sandbox: nothing you send reaches a channel.
|
|
24
|
+
ZIMMERSTACK_CONNECT_KEY=zsk_test_…
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
```ts
|
|
28
|
+
import { ZimmerStack } from "@zimmerstack/connect";
|
|
29
|
+
|
|
30
|
+
const zs = new ZimmerStack(); // reads ZIMMERSTACK_CONNECT_KEY; make one per process and reuse it
|
|
31
|
+
|
|
32
|
+
// The rate grid for a fortnight: rows are room types with their rate plans, columns are nights.
|
|
33
|
+
const grid = await zs.grid.load("2026-12-01", "2026-12-14");
|
|
34
|
+
|
|
35
|
+
// Save what a person changed. Nights are folded into ranges; a large save is split for you.
|
|
36
|
+
const accepted = await zs.grid.save({
|
|
37
|
+
rates: [
|
|
38
|
+
{ ratePlanId: 901, date: "2026-12-24", rate: 5200 }, // major units: 5200 = ₹5,200.00
|
|
39
|
+
{ ratePlanId: 901, date: "2026-12-25", rate: 5200 },
|
|
40
|
+
],
|
|
41
|
+
restrictions: [{ ratePlanId: 901, date: "2026-12-31", stopSell: true }], // close a night; never a zero price
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
// Accepted means it is in ZimmerStack's record and on its way to the channels.
|
|
45
|
+
const batch = await zs.batches.wait(accepted[0]!.batchId); // "landed", or still "pending" after five minutes
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## What it does so you do not have to
|
|
49
|
+
|
|
50
|
+
| The API's rule | What the client does |
|
|
51
|
+
|---|---|
|
|
52
|
+
| 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)`. |
|
|
53
|
+
| Budgets per minute | Reads the `RateLimit` header on every answer and waits before a budget runs out, instead of earning a refusal. |
|
|
54
|
+
| Writes are never a burst | Sends writes one at a time, in the order you made them. At most four reads at once. |
|
|
55
|
+
| 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. |
|
|
56
|
+
| 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. |
|
|
57
|
+
| A request has a size | Splits a write at 1,000 updates or 5,000 cells. |
|
|
58
|
+
| A refused key is not retried | After `API_KEY_INVALID`, `API_KEY_REVOKED` or `API_KEY_EXPIRED` it stops calling. |
|
|
59
|
+
| A test must not touch a real hotel | Refuses to write with a `zsk_live_` key under a test runner. |
|
|
60
|
+
|
|
61
|
+
## Everything it covers
|
|
62
|
+
|
|
63
|
+
```ts
|
|
64
|
+
zs.properties.list() // company keys: the hotels this key may act on
|
|
65
|
+
zs.property.get() // timezone, currency, this key's scopes, limits, usage, standing
|
|
66
|
+
zs.catalog.get() // room types and rate plans, with the ids every write uses
|
|
67
|
+
zs.catalog.upsertRoomTypes(…) / upsertRatePlans(…) / deleteRoomType(id) / deleteRatePlan(id)
|
|
68
|
+
|
|
69
|
+
zs.availability.get({ from, to }) / .set(updates)
|
|
70
|
+
zs.rates.get({ from, to }) / .set(updates) / .resend()
|
|
71
|
+
zs.restrictions.get({ from, to }) / .set(updates)
|
|
72
|
+
zs.grid.load(from, to) / zs.grid.save(edits)
|
|
73
|
+
|
|
74
|
+
zs.sync.get() // how far what you sent has travelled
|
|
75
|
+
zs.batches.get(batchId) / .wait(batchId)
|
|
76
|
+
|
|
77
|
+
zs.channels.list() // each booking site and the price modifier it holds
|
|
78
|
+
zs.channels.setModifier(channelId, steps)
|
|
79
|
+
|
|
80
|
+
zs.bookings.create(…) / .get(id) / .list(…) / .cancel(id) // your own booking engine
|
|
81
|
+
zs.channelBookings.list(…) / .get(id) / .all(…) // what the booking sites sent
|
|
82
|
+
zs.sandbox.bookings.create(…) / .cancel(id) / .modify(id, …) // pretend an OTA booked (test keys)
|
|
83
|
+
|
|
84
|
+
zs.request("GET /sync") // any operation of the contract by name, typed
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
Every request and answer is typed, with the API's own description on each field. Dates are plain
|
|
88
|
+
`YYYY-MM-DD` calendar days in the hotel's timezone. A price is sent in major units and read in minor
|
|
89
|
+
units (`rateMinor`); the grid helpers give and take major units.
|
|
90
|
+
|
|
91
|
+
## A different price on each booking site
|
|
92
|
+
|
|
93
|
+
One price per rate plan per night goes to every channel. A channel's **modifier** is what differs: a
|
|
94
|
+
few ordered steps applied to every price sent to that channel.
|
|
95
|
+
|
|
96
|
+
```ts
|
|
97
|
+
import { MODIFIER_TAKES_EFFECT, channelPrice } from "@zimmerstack/connect";
|
|
98
|
+
|
|
99
|
+
const { channels } = await zs.channels.list();
|
|
100
|
+
const booking = channels.find((c) => c.kind === "BookingCom")!;
|
|
101
|
+
|
|
102
|
+
// Booking.com is sent 18 % more, then 200 less. Needs the scope channel-modifiers:write.
|
|
103
|
+
await zs.channels.setModifier(booking.channelId, [
|
|
104
|
+
{ action: "increase", type: "percent", value: 18 },
|
|
105
|
+
{ action: "decrease", type: "fixed", value: 200 },
|
|
106
|
+
]);
|
|
107
|
+
|
|
108
|
+
channelPrice(4500, booking.modifier ?? []); // what Booking.com is sent for 4,500: show it beside the grid
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
`MODIFIER_TAKES_EFFECT` is the sentence to show where a person saves one: a modifier applies to
|
|
112
|
+
prices sent after the change, and prices already on the channel stay until those nights are sent
|
|
113
|
+
again. `zs.rates.resend()` sends them again, unchanged. A hotel may ask a few times a day, so make
|
|
114
|
+
it a button of its own and never call it automatically.
|
|
115
|
+
|
|
116
|
+
One call to `setModifier` moves every price on a channel. Call it when a person saved the setting;
|
|
117
|
+
never from a loop, a timer or a seed script.
|
|
118
|
+
|
|
119
|
+
## A software vendor's company key
|
|
120
|
+
|
|
121
|
+
```ts
|
|
122
|
+
const { properties } = await zs.properties.list();
|
|
123
|
+
const hotel = zs.forProperty(properties[0]!.id); // the same client and pace, acting on one hotel
|
|
124
|
+
await hotel.grid.load("2026-12-01", "2026-12-14");
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
## When the API says no
|
|
128
|
+
|
|
129
|
+
```ts
|
|
130
|
+
import { ZimmerStackError } from "@zimmerstack/connect";
|
|
131
|
+
|
|
132
|
+
try {
|
|
133
|
+
await zs.rates.set(updates);
|
|
134
|
+
} catch (err) {
|
|
135
|
+
if (!(err instanceof ZimmerStackError)) throw err;
|
|
136
|
+
err.code; // stable: "RATE_OUT_OF_BAND", "SCOPE_MISSING", "RATE_LIMITED", … branch on this
|
|
137
|
+
err.message; // a sentence for the person in front of the screen: show it
|
|
138
|
+
err.retryAfterSeconds; // when a budget refused: when to try again
|
|
139
|
+
err.retryable; // false = a verdict on the request. Fix it; never send it again.
|
|
140
|
+
}
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
The client has already waited and retried where that was worth it. Do not wrap its calls in a retry
|
|
144
|
+
loop of your own.
|
|
145
|
+
|
|
146
|
+
## Webhooks
|
|
147
|
+
|
|
148
|
+
```ts
|
|
149
|
+
import { verifyWebhook } from "@zimmerstack/connect";
|
|
150
|
+
|
|
151
|
+
export async function POST(request: Request) {
|
|
152
|
+
// The body exactly as it arrived, before any JSON parsing.
|
|
153
|
+
const event = await verifyWebhook(await request.text(), request.headers, process.env.ZIMMERSTACK_WEBHOOK_SECRET!);
|
|
154
|
+
// Deliveries are at-least-once: remember event.id and skip one you have seen.
|
|
155
|
+
if (event.type === "channel.booking.created") await save(event.data.booking);
|
|
156
|
+
return new Response(null, { status: 204 });
|
|
157
|
+
}
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
It throws `ZimmerStackWebhookError` for a delivery that is not ZimmerStack's or is older than five
|
|
161
|
+
minutes: answer 400 and do not act on the body.
|
|
162
|
+
|
|
163
|
+
## Options
|
|
164
|
+
|
|
165
|
+
```ts
|
|
166
|
+
new ZimmerStack({
|
|
167
|
+
apiKey, // default: process.env.ZIMMERSTACK_CONNECT_KEY
|
|
168
|
+
propertyId, // company keys: the hotel to act on (or use forProperty)
|
|
169
|
+
timeoutMs: 30_000, // one attempt
|
|
170
|
+
maxRetries: 3, // of what may pass later
|
|
171
|
+
maxWaitSeconds: 120, // the longest it waits for a budget before giving the refusal back
|
|
172
|
+
onEvent: (e) => log(e), // every answer, wait and retry, for your logs; never carries the key
|
|
173
|
+
fetch, // a stand-in for tests
|
|
174
|
+
});
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
## Testing your integration
|
|
178
|
+
|
|
179
|
+
Use a `zsk_test_` key (the hotel's owner creates a sandbox: Admin → Developers → API keys), or pass
|
|
180
|
+
a fake `fetch`. Nothing you do with a test key reaches a channel, and `zs.sandbox.bookings.create`
|
|
181
|
+
sends your webhook endpoint a real delivery.
|
|
182
|
+
|
|
183
|
+
## For AI coding agents
|
|
184
|
+
|
|
185
|
+
The package ships its own rules file. Copy it into the repository so the agent building on this
|
|
186
|
+
package follows it:
|
|
187
|
+
|
|
188
|
+
```bash
|
|
189
|
+
cp node_modules/@zimmerstack/connect/AGENTS.md ./AGENTS.md # or append it to CLAUDE.md
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
The whole API reference in one file an agent can read: <https://docs.zimmerstack.com/llms-full.txt>.
|
|
193
|
+
|
|
194
|
+
### An MCP server, so the agent looks things up instead of guessing
|
|
195
|
+
|
|
196
|
+
The package also carries an MCP server. Connect it to your coding agent and the agent can read the
|
|
197
|
+
rules, look up any part of the API, and try a call on your sandbox before it writes the code:
|
|
198
|
+
|
|
199
|
+
| Tool | What the agent gets |
|
|
200
|
+
|---|---|
|
|
201
|
+
| `zimmerstack_rules` | The rules for building on the API: the key, pacing, money and dates, a closing checklist. |
|
|
202
|
+
| `zimmerstack_reference` | Any operation, type, limit or error code, from the API's own contract. |
|
|
203
|
+
| `zimmerstack_sandbox_read` | One read on your sandbox: real ids and real shapes. |
|
|
204
|
+
| `zimmerstack_sandbox_write` | One write on your sandbox, to try a body before writing the code that sends it. |
|
|
205
|
+
|
|
206
|
+
```bash
|
|
207
|
+
# Claude Code
|
|
208
|
+
claude mcp add zimmerstack -- npx -y @zimmerstack/connect mcp
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
```json
|
|
212
|
+
// Cursor (.cursor/mcp.json) and Claude Code's project file (.mcp.json)
|
|
213
|
+
{ "mcpServers": { "zimmerstack": { "command": "npx", "args": ["-y", "@zimmerstack/connect", "mcp"] } } }
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
It runs on your own machine. It reads `ZIMMERSTACK_CONNECT_KEY` from the environment, or from your
|
|
217
|
+
project's `.env.local` or `.env`, so the key never goes into the agent's settings file. It uses the
|
|
218
|
+
key only when it is a sandbox key (`zsk_test_…`) and refuses a live one: an agent cannot change a
|
|
219
|
+
real hotel through it. Without a key the rules and the reference still work.
|
|
220
|
+
|
|
221
|
+
## Links
|
|
222
|
+
|
|
223
|
+
- Guides and reference: <https://docs.zimmerstack.com>
|
|
224
|
+
- Build a rate grid: <https://docs.zimmerstack.com/rate-grid>
|
|
225
|
+
- Prices per channel: <https://docs.zimmerstack.com/per-ota>
|
|
226
|
+
- Limits: <https://docs.zimmerstack.com/limits> · Errors: <https://docs.zimmerstack.com/errors>
|
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
import { type AvailabilityWrite, type BatchStatus, type Booking, type BookingCancel, type BookingCreate, type Catalog, type ChannelBooking, type ModifierResult, type OperationKey, type Operations, type RatePlansUpsert, type RatesResendAccepted, type RatesWrite, type RestrictionsWrite, type RoomTypesUpsert, type SandboxBookingCreate, type SandboxBookingModify, type WriteAccepted } from "./generated.js";
|
|
2
|
+
import { type Grid, type GridEdits, type ModifierStep } from "./grid.js";
|
|
3
|
+
export interface ZimmerStackOptions {
|
|
4
|
+
/**
|
|
5
|
+
* `zsk_test_…` (a sandbox: nothing reaches a channel) or `zsk_live_…`. Defaults to the environment
|
|
6
|
+
* variable `ZIMMERSTACK_CONNECT_KEY`, which is where it should live: never in code, a log or a browser.
|
|
7
|
+
*/
|
|
8
|
+
apiKey?: string;
|
|
9
|
+
/** A software vendor's company key only: the hotel every call acts on. See also `forProperty`. */
|
|
10
|
+
propertyId?: number;
|
|
11
|
+
/** Only for a local stand-in of the API while testing (http://localhost:…). The key is sent to no other host. */
|
|
12
|
+
baseUrl?: string;
|
|
13
|
+
/** A replacement for the global `fetch`, for tests. */
|
|
14
|
+
fetch?: typeof fetch;
|
|
15
|
+
/** How long one attempt may take. Default 30 s. */
|
|
16
|
+
timeoutMs?: number;
|
|
17
|
+
/** How many times a request that may pass later is sent again. Default 3 (four attempts in all), at most 5. */
|
|
18
|
+
maxRetries?: number;
|
|
19
|
+
/** The longest the client waits for a budget before giving the refusal back to you. Default 120 s. */
|
|
20
|
+
maxWaitSeconds?: number;
|
|
21
|
+
/**
|
|
22
|
+
* A live key under a test runner (NODE_ENV=test, Vitest, Jest, node --test) may read but not write,
|
|
23
|
+
* because a test that loops would change a real hotel. Set true only for a test that is meant to.
|
|
24
|
+
*/
|
|
25
|
+
allowLiveWritesInTests?: boolean;
|
|
26
|
+
/** What the client is doing, for your logs: every answer, every wait, every retry. Never carries the key. */
|
|
27
|
+
onEvent?: (event: ClientEvent) => void;
|
|
28
|
+
}
|
|
29
|
+
export type ClientEvent = {
|
|
30
|
+
type: "response";
|
|
31
|
+
operation: string;
|
|
32
|
+
status: number;
|
|
33
|
+
attempt: number;
|
|
34
|
+
ms: number;
|
|
35
|
+
} | {
|
|
36
|
+
type: "retry";
|
|
37
|
+
operation: string;
|
|
38
|
+
attempt: number;
|
|
39
|
+
waitMs: number;
|
|
40
|
+
reason: string;
|
|
41
|
+
} | {
|
|
42
|
+
type: "pace";
|
|
43
|
+
operation: string;
|
|
44
|
+
waitMs: number;
|
|
45
|
+
};
|
|
46
|
+
/** Per-call options of a write. */
|
|
47
|
+
export interface WriteOptions {
|
|
48
|
+
/**
|
|
49
|
+
* Your own key for this write (10 to 64 of A–Z a–z 0–9 _ -), when a retry may come from another
|
|
50
|
+
* process: the same key with the same body within 7 days replays the first answer instead of
|
|
51
|
+
* writing twice. Without one the client makes a fresh key and reuses it on its own retries.
|
|
52
|
+
*/
|
|
53
|
+
idempotencyKey?: string;
|
|
54
|
+
signal?: AbortSignal;
|
|
55
|
+
}
|
|
56
|
+
export interface ReadOptions {
|
|
57
|
+
signal?: AbortSignal;
|
|
58
|
+
}
|
|
59
|
+
type Op<K extends OperationKey> = Operations[K];
|
|
60
|
+
/** What `request` takes for an operation: its path values, its query, its body. */
|
|
61
|
+
export type RequestArgs<K extends OperationKey> = (Op<K>["path"] extends undefined ? {
|
|
62
|
+
path?: undefined;
|
|
63
|
+
} : {
|
|
64
|
+
path: Op<K>["path"];
|
|
65
|
+
}) & (Op<K>["query"] extends undefined ? {
|
|
66
|
+
query?: undefined;
|
|
67
|
+
} : {
|
|
68
|
+
query?: Op<K>["query"];
|
|
69
|
+
}) & (Op<K>["body"] extends undefined ? {
|
|
70
|
+
body?: undefined;
|
|
71
|
+
} : {
|
|
72
|
+
body: Op<K>["body"];
|
|
73
|
+
}) & WriteOptions;
|
|
74
|
+
/**
|
|
75
|
+
* The ZimmerStack Connect API, from your server.
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* import { ZimmerStack } from "@zimmerstack/connect";
|
|
79
|
+
*
|
|
80
|
+
* const zs = new ZimmerStack(); // reads ZIMMERSTACK_CONNECT_KEY
|
|
81
|
+
* const grid = await zs.grid.load("2026-12-01", "2026-12-14");
|
|
82
|
+
* await zs.grid.save({ rates: [{ ratePlanId: 901, date: "2026-12-24", rate: 5200 }] });
|
|
83
|
+
*
|
|
84
|
+
* Make one per process and reuse it: the pace it keeps is per instance.
|
|
85
|
+
*/
|
|
86
|
+
export declare class ZimmerStack {
|
|
87
|
+
#private;
|
|
88
|
+
/** "test" on a sandbox key: nothing you send reaches a channel. */
|
|
89
|
+
readonly mode: "live" | "test";
|
|
90
|
+
/** The hotel a company key acts on through this instance. */
|
|
91
|
+
readonly propertyId: number | undefined;
|
|
92
|
+
constructor(options?: ZimmerStackOptions);
|
|
93
|
+
/**
|
|
94
|
+
* A software vendor's company key: the same client, acting on one hotel. Shares this client's pace,
|
|
95
|
+
* so make as many as you have hotels.
|
|
96
|
+
*
|
|
97
|
+
* @example
|
|
98
|
+
* const { properties } = await zs.properties.list();
|
|
99
|
+
* for (const p of properties) await zs.forProperty(p.id).sync.get();
|
|
100
|
+
*/
|
|
101
|
+
forProperty(propertyId: number): ZimmerStack;
|
|
102
|
+
/** Never prints the key. */
|
|
103
|
+
toJSON(): {
|
|
104
|
+
mode: string;
|
|
105
|
+
propertyId: number | undefined;
|
|
106
|
+
};
|
|
107
|
+
/**
|
|
108
|
+
* Any operation of the contract by its name, typed. The methods below are this with friendlier names;
|
|
109
|
+
* use it for an operation they do not cover.
|
|
110
|
+
*
|
|
111
|
+
* @example
|
|
112
|
+
* const sync = await zs.request("GET /sync");
|
|
113
|
+
*/
|
|
114
|
+
request<K extends OperationKey>(operation: K, ...rest: {} extends RequestArgs<K> ? [args?: RequestArgs<K>] : [args: RequestArgs<K>]): Promise<Op<K>["response"]>;
|
|
115
|
+
readonly properties: {
|
|
116
|
+
/** The hotels this key may act on. A company key names one of them on every other call (`forProperty`). */
|
|
117
|
+
list: (options?: ReadOptions) => Promise<import("./generated.js").Properties>;
|
|
118
|
+
};
|
|
119
|
+
readonly property: {
|
|
120
|
+
/** The hotel: its timezone and currency, what this key may do, its own limits, what it has used, where it stands. */
|
|
121
|
+
get: (options?: ReadOptions) => Promise<import("./generated.js").Property>;
|
|
122
|
+
};
|
|
123
|
+
readonly catalog: {
|
|
124
|
+
/** Room types and rate plans, with the numeric ids every write uses. */
|
|
125
|
+
get: (options?: ReadOptions) => Promise<Catalog>;
|
|
126
|
+
/** Create or change room types by your own `ref`. Needs the scope catalog:write. */
|
|
127
|
+
upsertRoomTypes: (body: RoomTypesUpsert, options?: WriteOptions) => Promise<import("./generated.js").CatalogUpsertResult>;
|
|
128
|
+
/** Delete a room type; its rate plans go with it. */
|
|
129
|
+
deleteRoomType: (roomTypeId: number, options?: ReadOptions) => Promise<import("./generated.js").CatalogDeleteResult>;
|
|
130
|
+
/** Create or change rate plans by your own `ref`. */
|
|
131
|
+
upsertRatePlans: (body: RatePlansUpsert, options?: WriteOptions) => Promise<import("./generated.js").CatalogUpsertResult>;
|
|
132
|
+
deleteRatePlan: (ratePlanId: number, options?: ReadOptions) => Promise<import("./generated.js").CatalogDeleteResult>;
|
|
133
|
+
};
|
|
134
|
+
readonly availability: {
|
|
135
|
+
/** Rooms left to sell per room type per night, as ZimmerStack's record holds them. Up to 500 days. */
|
|
136
|
+
get: (range?: {
|
|
137
|
+
from?: string;
|
|
138
|
+
to?: string;
|
|
139
|
+
}, options?: ReadOptions) => Promise<import("./generated.js").AvailabilityRead>;
|
|
140
|
+
/**
|
|
141
|
+
* Set rooms left to sell: absolute numbers over date ranges. Answers when the values are in
|
|
142
|
+
* ZimmerStack's record (one answer per request sent; a large write is split for you).
|
|
143
|
+
*/
|
|
144
|
+
set: (updates: AvailabilityWrite["updates"], options?: WriteOptions) => Promise<WriteAccepted[]>;
|
|
145
|
+
};
|
|
146
|
+
readonly rates: {
|
|
147
|
+
/** Nightly prices per rate plan, in MINOR units (`rateMinor`), before any channel's modifier. */
|
|
148
|
+
get: (range?: {
|
|
149
|
+
from?: string;
|
|
150
|
+
to?: string;
|
|
151
|
+
}, options?: ReadOptions) => Promise<import("./generated.js").RatesRead>;
|
|
152
|
+
/**
|
|
153
|
+
* Set nightly prices in MAJOR units over date ranges (4500 = ₹4,500.00). `currency` may be left
|
|
154
|
+
* out: the hotel's own is filled in. To close a night use `restrictions.set` with stopSell,
|
|
155
|
+
* never a zero price.
|
|
156
|
+
*/
|
|
157
|
+
set: (updates: Array<Omit<RatesWrite["updates"][number], "currency"> & {
|
|
158
|
+
currency?: string;
|
|
159
|
+
}>, options?: WriteOptions) => Promise<WriteAccepted[]>;
|
|
160
|
+
/**
|
|
161
|
+
* Send the hotel's prices to its channels again, unchanged, so nights already there pick the
|
|
162
|
+
* current modifiers up. A hotel may ask a few times a day: make it a deliberate button, never
|
|
163
|
+
* automatic. Watch `rates.dirtyCells` on `sync.get()` fall to 0.
|
|
164
|
+
*/
|
|
165
|
+
resend: (options?: WriteOptions) => Promise<RatesResendAccepted>;
|
|
166
|
+
};
|
|
167
|
+
readonly restrictions: {
|
|
168
|
+
/** The stay rules per rate plan per night; null = no rule set for that field. */
|
|
169
|
+
get: (range?: {
|
|
170
|
+
from?: string;
|
|
171
|
+
to?: string;
|
|
172
|
+
}, options?: ReadOptions) => Promise<import("./generated.js").RestrictionsRead>;
|
|
173
|
+
/** Set stay rules over date ranges: stopSell, closedToArrival, closedToDeparture, minStayArrival, minStayThrough, maxStay. */
|
|
174
|
+
set: (updates: RestrictionsWrite["updates"], options?: WriteOptions) => Promise<WriteAccepted[]>;
|
|
175
|
+
};
|
|
176
|
+
readonly sync: {
|
|
177
|
+
/** How far what you sent has travelled: cells still on their way, the last error, where the integration stands. */
|
|
178
|
+
get: (options?: ReadOptions) => Promise<import("./generated.js").SyncStatus>;
|
|
179
|
+
};
|
|
180
|
+
readonly batches: {
|
|
181
|
+
/** One write, by the `batchId` its answer carried. */
|
|
182
|
+
get: (batchId: string, options?: ReadOptions) => Promise<BatchStatus>;
|
|
183
|
+
/**
|
|
184
|
+
* Wait for a write to reach the channels, asking no more often than every 15 seconds, for at most
|
|
185
|
+
* five minutes. Returns the last status: if it is still "pending", say "still syncing" and let the
|
|
186
|
+
* person look again later. Availability lands in seconds; a full calendar of prices takes minutes.
|
|
187
|
+
*/
|
|
188
|
+
wait: (batchId: string, options?: {
|
|
189
|
+
timeoutMs?: number;
|
|
190
|
+
intervalMs?: number;
|
|
191
|
+
signal?: AbortSignal;
|
|
192
|
+
}) => Promise<BatchStatus>;
|
|
193
|
+
};
|
|
194
|
+
readonly channels: {
|
|
195
|
+
/**
|
|
196
|
+
* The connected channels (Booking.com, MakeMyTrip, …), each with the price modifier it holds:
|
|
197
|
+
* `[]` = prices go as they are; `null` = a rule set by hand that this API cannot express.
|
|
198
|
+
*/
|
|
199
|
+
list: (options?: ReadOptions) => Promise<import("./generated.js").Channels>;
|
|
200
|
+
/**
|
|
201
|
+
* Replace a channel's modifier with these steps (`[]` removes it). Needs the scope
|
|
202
|
+
* channel-modifiers:write.
|
|
203
|
+
*
|
|
204
|
+
* ONE CALL MOVES EVERY PRICE SENT TO THAT CHANNEL FROM THEN ON. Call it when a person saved the
|
|
205
|
+
* setting; never from a loop, a timer or a test against a live key. Prices already on the channel
|
|
206
|
+
* stay as they are until those nights are sent again (`rates.resend`).
|
|
207
|
+
*/
|
|
208
|
+
setModifier: (channelId: string, steps: ModifierStep[], options?: WriteOptions) => Promise<ModifierResult>;
|
|
209
|
+
};
|
|
210
|
+
readonly bookings: {
|
|
211
|
+
/** Bookings this integration created, newest first. */
|
|
212
|
+
list: (query?: Op<"GET /bookings">["query"], options?: ReadOptions) => Promise<import("./generated.js").BookingsList>;
|
|
213
|
+
/**
|
|
214
|
+
* Create a booking in the hotel's PMS. Always send `externalReference` (your own reservation id):
|
|
215
|
+
* the same value returns the same booking, which makes every retry safe.
|
|
216
|
+
*/
|
|
217
|
+
create: (body: BookingCreate, options?: WriteOptions) => Promise<Booking>;
|
|
218
|
+
get: (bookingId: number, options?: ReadOptions) => Promise<Booking>;
|
|
219
|
+
/** Cancel a booking this integration created; its nights open again on the channels. */
|
|
220
|
+
cancel: (bookingId: number, body?: BookingCancel, options?: ReadOptions) => Promise<Booking>;
|
|
221
|
+
};
|
|
222
|
+
readonly channelBookings: {
|
|
223
|
+
/** OTA bookings the channel manager delivered, in the webhook's shape. Follow `nextCursor`, or use `all`. */
|
|
224
|
+
list: (query?: Op<"GET /channel-bookings">["query"], options?: ReadOptions) => Promise<import("./generated.js").ChannelBookingsList>;
|
|
225
|
+
get: (bookingId: number, options?: ReadOptions) => Promise<ChannelBooking>;
|
|
226
|
+
/**
|
|
227
|
+
* Every OTA booking changed since `since`, page by page, for reconciling what your webhook missed.
|
|
228
|
+
*
|
|
229
|
+
* @example
|
|
230
|
+
* for await (const booking of zs.channelBookings.all({ since: lastSeen })) save(booking);
|
|
231
|
+
*/
|
|
232
|
+
all: (query?: Omit<NonNullable<Op<"GET /channel-bookings">["query"]>, "cursor">, options?: ReadOptions) => AsyncGenerator<ChannelBooking, void, undefined>;
|
|
233
|
+
};
|
|
234
|
+
readonly sandbox: {
|
|
235
|
+
bookings: {
|
|
236
|
+
list: (options?: ReadOptions) => Promise<import("./generated.js").SandboxBookingsList>;
|
|
237
|
+
/** Pretend an OTA booked: the booking, the availability moved down, and the real webhook to your endpoint. */
|
|
238
|
+
create: (body: SandboxBookingCreate, options?: WriteOptions) => Promise<import("./generated.js").SandboxBooking>;
|
|
239
|
+
cancel: (bookingId: number, options?: ReadOptions) => Promise<import("./generated.js").SandboxBooking>;
|
|
240
|
+
modify: (bookingId: number, body: SandboxBookingModify, options?: ReadOptions) => Promise<import("./generated.js").SandboxBooking>;
|
|
241
|
+
};
|
|
242
|
+
};
|
|
243
|
+
readonly grid: {
|
|
244
|
+
/**
|
|
245
|
+
* The whole grid for a window, ready for a screen: rows are room types with their rate plans,
|
|
246
|
+
* columns are nights. Three reads (four the first time). A window may span 500 days; a screen
|
|
247
|
+
* needs 14 to 60.
|
|
248
|
+
*/
|
|
249
|
+
load: (from: string, to: string, options?: ReadOptions) => Promise<Grid>;
|
|
250
|
+
/**
|
|
251
|
+
* Save what a person changed: single nights in, the fewest ranges out, one request per resource,
|
|
252
|
+
* one after another. Each answer carries a `batchId`: the values are in ZimmerStack's record and
|
|
253
|
+
* on their way to the channels.
|
|
254
|
+
*/
|
|
255
|
+
save: (edits: GridEdits, options?: {
|
|
256
|
+
signal?: AbortSignal;
|
|
257
|
+
}) => Promise<WriteAccepted[]>;
|
|
258
|
+
};
|
|
259
|
+
}
|
|
260
|
+
export {};
|