@zimmerstack/connect 0.1.0 → 0.3.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 +26 -3
- package/README.md +50 -11
- package/dist/cjs/client.d.ts +21 -1
- package/dist/cjs/client.js +83 -11
- package/dist/cjs/generated.d.ts +30 -9
- package/dist/cjs/generated.js +4 -1
- package/dist/cjs/index.d.ts +2 -2
- package/dist/cjs/index.js +6 -1
- package/dist/cjs/webhooks.d.ts +43 -1
- package/dist/cjs/webhooks.js +29 -1
- package/dist/esm/client.d.ts +21 -1
- package/dist/esm/client.js +83 -11
- package/dist/esm/generated.d.ts +30 -9
- package/dist/esm/generated.js +4 -1
- package/dist/esm/index.d.ts +2 -2
- package/dist/esm/index.js +1 -1
- package/dist/esm/mcp/reference.generated.js +242 -11
- package/dist/esm/webhooks.d.ts +43 -1
- package/dist/esm/webhooks.js +26 -0
- package/package.json +1 -1
package/AGENTS.md
CHANGED
|
@@ -12,12 +12,20 @@ https://docs.zimmerstack.com/llms-full.txt
|
|
|
12
12
|
file that is committed, a log line, an error message, a URL, a test fixture or anything a browser
|
|
13
13
|
or a mobile app receives. Never print it. `new ZimmerStack()` reads it by itself.
|
|
14
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.
|
|
15
|
+
person's own frontend calls their own server, and the server calls ZimmerStack. Never put the key in
|
|
16
|
+
a variable a bundler sends to the browser (`VITE_`, `NEXT_PUBLIC_`, `REACT_APP_`, `EXPO_PUBLIC_`).
|
|
17
|
+
An app with no server gets the smallest one: https://docs.zimmerstack.com/sdk#no-server. A plain
|
|
18
|
+
`fetch` from a browser is refused too ("Failed to fetch"), on purpose.
|
|
16
19
|
- `zsk_test_…` is a sandbox: nothing reaches a channel. Build and test with it. `zsk_live_…` is a real
|
|
17
20
|
hotel. The package refuses to WRITE with a live key under a test runner; never switch that off to
|
|
18
21
|
make a test pass.
|
|
19
22
|
- A software vendor's company key acts on one hotel at a time: `zs.forProperty(propertyId)`
|
|
20
|
-
(`zs.properties.list()` names them)
|
|
23
|
+
(`zs.properties.list()` names them), or `ZIMMERSTACK_PROPERTY_ID` in the environment for an app that
|
|
24
|
+
serves one hotel. A test company key that reaches one sandbox finds it by itself; with several,
|
|
25
|
+
name one; a live key never guesses.
|
|
26
|
+
- No key yet: a software company signs up, free, at https://www.zimmerstack.com/partners/pms-companies#join
|
|
27
|
+
and makes test keys in the partner portal (Developers); a hotel's owner makes one in Admin →
|
|
28
|
+
Developers → API keys.
|
|
21
29
|
|
|
22
30
|
## Let the package pace; never work around it
|
|
23
31
|
|
|
@@ -36,7 +44,7 @@ https://docs.zimmerstack.com/llms-full.txt
|
|
|
36
44
|
|
|
37
45
|
## Money and dates
|
|
38
46
|
|
|
39
|
-
- A price is SENT in major units (4500 =
|
|
47
|
+
- A price is SENT in major units (4500 = 4,500.00 of the hotel's own currency) with that currency, and READ in minor
|
|
40
48
|
units (`rateMinor`). `zs.grid.load` gives major units; `zs.grid.save` takes them.
|
|
41
49
|
- A date is a plain `YYYY-MM-DD` calendar day in the hotel's timezone. Never build one with
|
|
42
50
|
`new Date()` arithmetic in local time; use `eachDate(from, to)`.
|
|
@@ -56,6 +64,20 @@ https://docs.zimmerstack.com/llms-full.txt
|
|
|
56
64
|
- Keep the grid on the price before any modifier; show a channel's price beside it with
|
|
57
65
|
`channelPrice(rate, steps)`.
|
|
58
66
|
|
|
67
|
+
## Website bookings: apply them before you push room counts
|
|
68
|
+
|
|
69
|
+
- When the hotel also sells on its own website through ZimmerStack's booking engine, those bookings
|
|
70
|
+
reach you as the webhooks `direct.booking.created` and `direct.booking.cancelled` (the endpoint must
|
|
71
|
+
list those two types) and by `zs.directBookings.all({ since })` (scope `direct-bookings:read`). They
|
|
72
|
+
are not OTA bookings: `isWebsiteBookingEvent(event)` tells them apart, `channel.otaName` is `"Website"`
|
|
73
|
+
and `finance` is null. There is no modified event.
|
|
74
|
+
- A website booking takes one room off the count the channels hold, at once. A PMS that pushes absolute
|
|
75
|
+
room counts must apply the booking to its own calendar BEFORE its next `zs.availability.set` or
|
|
76
|
+
`zs.grid.save`, or that push puts the sold room back on sale. Read `zs.directBookings.all` before a
|
|
77
|
+
full push. Nothing on our side stops the count from going up.
|
|
78
|
+
- You cannot cancel a website booking through this package: the guest cancels on the booking page, or
|
|
79
|
+
the hotel does in ZimmerStack.
|
|
80
|
+
|
|
59
81
|
## Errors
|
|
60
82
|
|
|
61
83
|
```ts
|
|
@@ -97,3 +119,4 @@ these tools.
|
|
|
97
119
|
- [ ] Errors show `err.message` to the person and branch on `err.code`.
|
|
98
120
|
- [ ] Tests run against a `zsk_test_` key or a fake `fetch`; none needs a live key.
|
|
99
121
|
- [ ] Where a modifier is saved, the screen says when it takes effect, and the re-send is its own button.
|
|
122
|
+
- [ ] A PMS that pushes room counts applies every website booking to its own calendar before it pushes.
|
package/README.md
CHANGED
|
@@ -13,10 +13,17 @@ npm install @zimmerstack/connect
|
|
|
13
13
|
|
|
14
14
|
Node 20 or newer. **Server only**: the key can change a hotel's prices on every channel, so the
|
|
15
15
|
package refuses to start in a browser or a mobile app. Your frontend calls your server; your server
|
|
16
|
-
calls ZimmerStack.
|
|
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.
|
|
17
19
|
|
|
18
20
|
## Start
|
|
19
21
|
|
|
22
|
+
**Get a test key.** A software company: [sign up free](https://www.zimmerstack.com/partners/pms-companies#join)
|
|
23
|
+
(your sandbox is made at sign-up), then the [partner portal](https://partner.zimmerstack.com/login) →
|
|
24
|
+
Developers → Create key. A hotel's own developer: the owner makes one in Admin → Developers → API keys.
|
|
25
|
+
A working app to start from: <https://github.com/zimmerstack/connect-starter>.
|
|
26
|
+
|
|
20
27
|
Put the key in the environment, never in code:
|
|
21
28
|
|
|
22
29
|
```bash
|
|
@@ -35,7 +42,7 @@ const grid = await zs.grid.load("2026-12-01", "2026-12-14");
|
|
|
35
42
|
// Save what a person changed. Nights are folded into ranges; a large save is split for you.
|
|
36
43
|
const accepted = await zs.grid.save({
|
|
37
44
|
rates: [
|
|
38
|
-
{ ratePlanId: 901, date: "2026-12-24", rate: 5200 }, // major units: 5200 =
|
|
45
|
+
{ ratePlanId: 901, date: "2026-12-24", rate: 5200 }, // major units, the hotel's currency: 5200 = 5,200.00
|
|
39
46
|
{ ratePlanId: 901, date: "2026-12-25", rate: 5200 },
|
|
40
47
|
],
|
|
41
48
|
restrictions: [{ ratePlanId: 901, date: "2026-12-31", stopSell: true }], // close a night; never a zero price
|
|
@@ -79,7 +86,8 @@ zs.channels.setModifier(channelId, steps)
|
|
|
79
86
|
|
|
80
87
|
zs.bookings.create(…) / .get(id) / .list(…) / .cancel(id) // your own booking engine
|
|
81
88
|
zs.channelBookings.list(…) / .get(id) / .all(…) // what the booking sites sent
|
|
82
|
-
zs.
|
|
89
|
+
zs.directBookings.list(…) / .get(id) / .all(…) // what guests booked on the hotel's own website
|
|
90
|
+
zs.sandbox.bookings.create(…) / .cancel(id) / .modify(id, …) // pretend an OTA or the website booked (test keys)
|
|
83
91
|
|
|
84
92
|
zs.request("GET /sync") // any operation of the contract by name, typed
|
|
85
93
|
```
|
|
@@ -118,12 +126,19 @@ never from a loop, a timer or a seed script.
|
|
|
118
126
|
|
|
119
127
|
## A software vendor's company key
|
|
120
128
|
|
|
129
|
+
A company key reaches many hotels, so every call names one. A **test** company key reaches your
|
|
130
|
+
sandboxes; while you have one, the client finds it by itself and the Start example works unchanged.
|
|
131
|
+
With several, name one. A live key never guesses.
|
|
132
|
+
|
|
121
133
|
```ts
|
|
122
134
|
const { properties } = await zs.properties.list();
|
|
123
135
|
const hotel = zs.forProperty(properties[0]!.id); // the same client and pace, acting on one hotel
|
|
124
136
|
await hotel.grid.load("2026-12-01", "2026-12-14");
|
|
125
137
|
```
|
|
126
138
|
|
|
139
|
+
An app that serves one hotel can name it once instead: `ZIMMERSTACK_PROPERTY_ID=61` in the
|
|
140
|
+
environment (or `new ZimmerStack({ propertyId: 61 })`).
|
|
141
|
+
|
|
127
142
|
## When the API says no
|
|
128
143
|
|
|
129
144
|
```ts
|
|
@@ -146,13 +161,14 @@ loop of your own.
|
|
|
146
161
|
## Webhooks
|
|
147
162
|
|
|
148
163
|
```ts
|
|
149
|
-
import { verifyWebhook } from "@zimmerstack/connect";
|
|
164
|
+
import { isOtaBookingEvent, isWebsiteBookingEvent, verifyWebhook } from "@zimmerstack/connect";
|
|
150
165
|
|
|
151
166
|
export async function POST(request: Request) {
|
|
152
167
|
// The body exactly as it arrived, before any JSON parsing.
|
|
153
168
|
const event = await verifyWebhook(await request.text(), request.headers, process.env.ZIMMERSTACK_WEBHOOK_SECRET!);
|
|
154
169
|
// Deliveries are at-least-once: remember event.id and skip one you have seen.
|
|
155
|
-
if (event
|
|
170
|
+
if (isOtaBookingEvent(event)) await save(event.data.booking); // channel.booking.created, .modified, .cancelled
|
|
171
|
+
if (isWebsiteBookingEvent(event)) await applyToMyCalendar(event.data.booking); // direct.booking.created, .cancelled
|
|
156
172
|
return new Response(null, { status: 204 });
|
|
157
173
|
}
|
|
158
174
|
```
|
|
@@ -160,12 +176,34 @@ export async function POST(request: Request) {
|
|
|
160
176
|
It throws `ZimmerStackWebhookError` for a delivery that is not ZimmerStack's or is older than five
|
|
161
177
|
minutes: answer 400 and do not act on the body.
|
|
162
178
|
|
|
179
|
+
## Bookings from the hotel's own website
|
|
180
|
+
|
|
181
|
+
A hotel that sells on its own website through ZimmerStack's booking engine, and keeps its own PMS,
|
|
182
|
+
gets those bookings in a family of their own: the webhooks `direct.booking.created` and
|
|
183
|
+
`direct.booking.cancelled` (the endpoint must list both types; one registered earlier receives none
|
|
184
|
+
until its owner ticks them), and `zs.directBookings` for the pull (scope `direct-bookings:read`). The
|
|
185
|
+
booking object is the one OTA bookings use. `channel.otaName` is `"Website"`, `finance` is null, and
|
|
186
|
+
`amounts.paid` is what the guest paid online. There is no modified event.
|
|
187
|
+
|
|
188
|
+
**Apply a website booking to your own calendar before your next push of room counts.** The booking
|
|
189
|
+
takes one room off the count the channels hold at once; a push of the old absolute count would put it
|
|
190
|
+
back on sale. Read `zs.directBookings.all` before a full push:
|
|
191
|
+
|
|
192
|
+
```ts
|
|
193
|
+
for await (const booking of zs.directBookings.all({ since: lastSeen })) applyToMyCalendar(booking);
|
|
194
|
+
await zs.grid.save(edits); // only now
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
A guest cancels on the booking page, or the hotel cancels in ZimmerStack; there is no way to cancel
|
|
198
|
+
one through the API yet. To try it with a test key, `zs.sandbox.bookings.create({ …, otaName: "Website" })`.
|
|
199
|
+
Guide: <https://docs.zimmerstack.com/website-bookings>
|
|
200
|
+
|
|
163
201
|
## Options
|
|
164
202
|
|
|
165
203
|
```ts
|
|
166
204
|
new ZimmerStack({
|
|
167
205
|
apiKey, // default: process.env.ZIMMERSTACK_CONNECT_KEY
|
|
168
|
-
propertyId, // company keys: the hotel to act on (or use forProperty)
|
|
206
|
+
propertyId, // company keys: the hotel to act on; default ZIMMERSTACK_PROPERTY_ID (or use forProperty)
|
|
169
207
|
timeoutMs: 30_000, // one attempt
|
|
170
208
|
maxRetries: 3, // of what may pass later
|
|
171
209
|
maxWaitSeconds: 120, // the longest it waits for a budget before giving the refusal back
|
|
@@ -176,17 +214,17 @@ new ZimmerStack({
|
|
|
176
214
|
|
|
177
215
|
## Testing your integration
|
|
178
216
|
|
|
179
|
-
Use a `zsk_test_` key (
|
|
180
|
-
a fake `fetch`. Nothing you do with a test key reaches a channel, and `zs.sandbox.bookings.create`
|
|
217
|
+
Use a `zsk_test_` key (a software company: the partner portal → Developers; a hotel's owner: Admin →
|
|
218
|
+
Developers → API keys), or pass a fake `fetch`. Nothing you do with a test key reaches a channel, and `zs.sandbox.bookings.create`
|
|
181
219
|
sends your webhook endpoint a real delivery.
|
|
182
220
|
|
|
183
221
|
## For AI coding agents
|
|
184
222
|
|
|
185
|
-
The package ships its own rules file.
|
|
186
|
-
package follows it:
|
|
223
|
+
The package ships its own rules file. Add it to the repository's rules so the agent building on this
|
|
224
|
+
package follows it. Append, never copy over: Next.js and other tools write their own `AGENTS.md`.
|
|
187
225
|
|
|
188
226
|
```bash
|
|
189
|
-
|
|
227
|
+
cat node_modules/@zimmerstack/connect/AGENTS.md >> AGENTS.md # or >> CLAUDE.md
|
|
190
228
|
```
|
|
191
229
|
|
|
192
230
|
The whole API reference in one file an agent can read: <https://docs.zimmerstack.com/llms-full.txt>.
|
|
@@ -223,4 +261,5 @@ real hotel through it. Without a key the rules and the reference still work.
|
|
|
223
261
|
- Guides and reference: <https://docs.zimmerstack.com>
|
|
224
262
|
- Build a rate grid: <https://docs.zimmerstack.com/rate-grid>
|
|
225
263
|
- Prices per channel: <https://docs.zimmerstack.com/per-ota>
|
|
264
|
+
- Bookings from the hotel's own website: <https://docs.zimmerstack.com/website-bookings>
|
|
226
265
|
- Limits: <https://docs.zimmerstack.com/limits> · Errors: <https://docs.zimmerstack.com/errors>
|
package/dist/cjs/client.d.ts
CHANGED
|
@@ -231,10 +231,30 @@ export declare class ZimmerStack {
|
|
|
231
231
|
*/
|
|
232
232
|
all: (query?: Omit<NonNullable<Op<"GET /channel-bookings">["query"]>, "cursor">, options?: ReadOptions) => AsyncGenerator<ChannelBooking, void, undefined>;
|
|
233
233
|
};
|
|
234
|
+
readonly directBookings: {
|
|
235
|
+
/**
|
|
236
|
+
* Website bookings, in the webhook's shape (`direct.booking.*`), cancellations included. Scope
|
|
237
|
+
* `direct-bookings:read`. Follow `nextCursor`, or use `all`.
|
|
238
|
+
*/
|
|
239
|
+
list: (query?: Op<"GET /direct-bookings">["query"], options?: ReadOptions) => Promise<import("./generated.js").ChannelBookingsList>;
|
|
240
|
+
get: (bookingId: number, options?: ReadOptions) => Promise<ChannelBooking>;
|
|
241
|
+
/**
|
|
242
|
+
* Every website booking changed since `since`, page by page. A PMS that pushes room counts reads this
|
|
243
|
+
* before a full push, so the sold rooms are in its own calendar first.
|
|
244
|
+
*
|
|
245
|
+
* @example
|
|
246
|
+
* for await (const booking of zs.directBookings.all({ since: lastSeen })) applyToMyCalendar(booking);
|
|
247
|
+
*/
|
|
248
|
+
all: (query?: Omit<NonNullable<Op<"GET /direct-bookings">["query"]>, "cursor">, options?: ReadOptions) => AsyncGenerator<ChannelBooking, void, undefined>;
|
|
249
|
+
};
|
|
234
250
|
readonly sandbox: {
|
|
235
251
|
bookings: {
|
|
236
252
|
list: (options?: ReadOptions) => Promise<import("./generated.js").SandboxBookingsList>;
|
|
237
|
-
/**
|
|
253
|
+
/**
|
|
254
|
+
* Pretend an OTA booked: the booking, the availability moved down, and the real webhook to your endpoint.
|
|
255
|
+
* With `otaName: "Website"` it pretends a guest booked on the hotel's own website instead, and the webhook
|
|
256
|
+
* is `direct.booking.created`.
|
|
257
|
+
*/
|
|
238
258
|
create: (body: SandboxBookingCreate, options?: WriteOptions) => Promise<import("./generated.js").SandboxBooking>;
|
|
239
259
|
cancel: (bookingId: number, options?: ReadOptions) => Promise<import("./generated.js").SandboxBooking>;
|
|
240
260
|
modify: (bookingId: number, body: SandboxBookingModify, options?: ReadOptions) => Promise<import("./generated.js").SandboxBooking>;
|
package/dist/cjs/client.js
CHANGED
|
@@ -66,10 +66,14 @@ class Core {
|
|
|
66
66
|
#writeTail = Promise.resolve();
|
|
67
67
|
#dead;
|
|
68
68
|
catalogs = new Map();
|
|
69
|
+
/** A sandbox company key's one hotel, found once when a call asked for a hotel and none was named. */
|
|
70
|
+
soleSandboxProperty;
|
|
71
|
+
/** The same, once known: sent with every later call that names no hotel, so the refusal is met once. */
|
|
72
|
+
soleSandboxId;
|
|
69
73
|
constructor(options) {
|
|
70
74
|
const g = globalThis;
|
|
71
75
|
if ((typeof g.window !== "undefined" && typeof g.window.document !== "undefined") || g.navigator?.product === "ReactNative") {
|
|
72
|
-
throw new errors_ts_1.ZimmerStackUsageError("@zimmerstack/connect runs on a server only. A key in a browser or a mobile app can be read by anyone and can change a hotel's prices on every channel: call your own server from here, and ZimmerStack from your server.");
|
|
76
|
+
throw new errors_ts_1.ZimmerStackUsageError("@zimmerstack/connect runs on a server only. A key in a browser or a mobile app can be read by anyone and can change a hotel's prices on every channel: call your own server from here, and ZimmerStack from your server (https://docs.zimmerstack.com/sdk#no-server shows the smallest one). If a key was built into this page, anyone can read it now: revoke it and make a new one.");
|
|
73
77
|
}
|
|
74
78
|
const key = options.apiKey ?? env("ZIMMERSTACK_CONNECT_KEY");
|
|
75
79
|
if (!key)
|
|
@@ -274,10 +278,16 @@ class ZimmerStack {
|
|
|
274
278
|
handoff = undefined;
|
|
275
279
|
this.#core = shared ?? new Core(options);
|
|
276
280
|
this.mode = this.#core.mode;
|
|
277
|
-
|
|
281
|
+
// A company key's hotel: the option, else (for a client made from the environment) ZIMMERSTACK_PROPERTY_ID.
|
|
282
|
+
const fromEnv = shared ? undefined : env("ZIMMERSTACK_PROPERTY_ID")?.trim();
|
|
283
|
+
if (fromEnv && !/^[1-9]\d*$/.test(fromEnv)) {
|
|
284
|
+
throw new errors_ts_1.ZimmerStackUsageError("ZIMMERSTACK_PROPERTY_ID must be a property's numeric id (zs.properties.list() names them)");
|
|
285
|
+
}
|
|
286
|
+
const propertyId = options.propertyId ?? (fromEnv ? Number(fromEnv) : undefined);
|
|
287
|
+
if (propertyId !== undefined && (!Number.isInteger(propertyId) || propertyId <= 0)) {
|
|
278
288
|
throw new errors_ts_1.ZimmerStackUsageError("propertyId must be a property's numeric id (zs.properties.list() names them)");
|
|
279
289
|
}
|
|
280
|
-
this.propertyId =
|
|
290
|
+
this.propertyId = propertyId;
|
|
281
291
|
}
|
|
282
292
|
/**
|
|
283
293
|
* A software vendor's company key: the same client, acting on one hotel. Shares this client's pace,
|
|
@@ -327,8 +337,9 @@ class ZimmerStack {
|
|
|
327
337
|
if (value !== undefined && value !== null)
|
|
328
338
|
url.searchParams.set(name, String(value));
|
|
329
339
|
const headers = { authorization: this.#core.authorization(), accept: "application/json", "user-agent": `zimmerstack-connect-node/${generated_ts_1.SDK_VERSION}` };
|
|
330
|
-
|
|
331
|
-
|
|
340
|
+
const hotel = this.propertyId ?? (operation === "GET /properties" ? undefined : this.#core.soleSandboxId);
|
|
341
|
+
if (hotel)
|
|
342
|
+
headers[generated_ts_1.PROPERTY_HEADER] = String(hotel);
|
|
332
343
|
const body = args.body === undefined ? undefined : JSON.stringify(args.body);
|
|
333
344
|
if (body !== undefined)
|
|
334
345
|
headers["content-type"] = "application/json";
|
|
@@ -339,8 +350,47 @@ class ZimmerStack {
|
|
|
339
350
|
}
|
|
340
351
|
headers[generated_ts_1.IDEMPOTENCY_HEADER] = args.idempotencyKey ?? crypto.randomUUID();
|
|
341
352
|
}
|
|
342
|
-
const
|
|
343
|
-
|
|
353
|
+
const wire = { operation, method, url, headers, body, write: method !== "GET", resendable: method === "GET" || meta.idempotent, signal: args.signal };
|
|
354
|
+
try {
|
|
355
|
+
return (await this.#core.send(wire));
|
|
356
|
+
}
|
|
357
|
+
catch (err) {
|
|
358
|
+
// A company key that named no hotel. The API refused before anything ran, so sending again is safe.
|
|
359
|
+
if (!(err instanceof errors_ts_1.ZimmerStackError) || err.code !== "PROPERTY_REQUIRED" || this.propertyId !== undefined)
|
|
360
|
+
throw err;
|
|
361
|
+
const sole = await this.#soleSandboxProperty(args.signal);
|
|
362
|
+
if (sole === undefined) {
|
|
363
|
+
throw new errors_ts_1.ZimmerStackError({
|
|
364
|
+
status: err.status,
|
|
365
|
+
code: err.code,
|
|
366
|
+
message: "This is a company key: say which hotel each call acts on. Use zs.forProperty(id), new ZimmerStack({ propertyId }) or the environment variable ZIMMERSTACK_PROPERTY_ID; zs.properties.list() names the hotels this key reaches.",
|
|
367
|
+
operation,
|
|
368
|
+
details: err.details,
|
|
369
|
+
retryable: false,
|
|
370
|
+
});
|
|
371
|
+
}
|
|
372
|
+
// The same request (same idempotency key) naming the hotel, on its own copy of the headers.
|
|
373
|
+
return (await this.#core.send({ ...wire, headers: { ...headers, [generated_ts_1.PROPERTY_HEADER]: String(sole) } }));
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
/**
|
|
377
|
+
* The one hotel a SANDBOX company key reaches (its sandbox), so the first call of a new integration works
|
|
378
|
+
* without naming it. A live key never guesses: a hotel it acts on is always named.
|
|
379
|
+
*/
|
|
380
|
+
#soleSandboxProperty(signal) {
|
|
381
|
+
if (this.mode !== "test")
|
|
382
|
+
return Promise.resolve(undefined);
|
|
383
|
+
this.#core.soleSandboxProperty ??= this.request("GET /properties", { signal })
|
|
384
|
+
.then((list) => {
|
|
385
|
+
const only = list.keyKind === "company" && list.properties.length === 1 && list.properties[0].sandbox ? list.properties[0].id : undefined;
|
|
386
|
+
this.#core.soleSandboxId = only;
|
|
387
|
+
return only;
|
|
388
|
+
})
|
|
389
|
+
.catch(() => {
|
|
390
|
+
this.#core.soleSandboxProperty = undefined; // a failed lookup is asked again next time
|
|
391
|
+
return undefined;
|
|
392
|
+
});
|
|
393
|
+
return this.#core.soleSandboxProperty;
|
|
344
394
|
}
|
|
345
395
|
/* ── which hotel ── */
|
|
346
396
|
properties = {
|
|
@@ -499,12 +549,30 @@ class ZimmerStack {
|
|
|
499
549
|
* @example
|
|
500
550
|
* for await (const booking of zs.channelBookings.all({ since: lastSeen })) save(booking);
|
|
501
551
|
*/
|
|
502
|
-
all: (query, options) => this.#
|
|
552
|
+
all: (query, options) => this.#allPages((cursor) => this.channelBookings.list({ limit: 100, ...query, cursor }, options)),
|
|
553
|
+
};
|
|
554
|
+
/* ── bookings guests made on the hotel's own website (our booking engine) ── */
|
|
555
|
+
directBookings = {
|
|
556
|
+
/**
|
|
557
|
+
* Website bookings, in the webhook's shape (`direct.booking.*`), cancellations included. Scope
|
|
558
|
+
* `direct-bookings:read`. Follow `nextCursor`, or use `all`.
|
|
559
|
+
*/
|
|
560
|
+
list: (query, options) => this.request("GET /direct-bookings", { query, ...options }),
|
|
561
|
+
get: (bookingId, options) => this.request("GET /direct-bookings/{bookingId}", { path: { bookingId }, ...options }),
|
|
562
|
+
/**
|
|
563
|
+
* Every website booking changed since `since`, page by page. A PMS that pushes room counts reads this
|
|
564
|
+
* before a full push, so the sold rooms are in its own calendar first.
|
|
565
|
+
*
|
|
566
|
+
* @example
|
|
567
|
+
* for await (const booking of zs.directBookings.all({ since: lastSeen })) applyToMyCalendar(booking);
|
|
568
|
+
*/
|
|
569
|
+
all: (query, options) => this.#allPages((cursor) => this.directBookings.list({ limit: 100, ...query, cursor }, options)),
|
|
503
570
|
};
|
|
504
|
-
|
|
571
|
+
/** Follow a booking list's `nextCursor` to its last page. */
|
|
572
|
+
async *#allPages(read) {
|
|
505
573
|
let cursor;
|
|
506
574
|
do {
|
|
507
|
-
const page = await
|
|
575
|
+
const page = await read(cursor);
|
|
508
576
|
yield* page.items;
|
|
509
577
|
cursor = page.nextCursor ?? undefined;
|
|
510
578
|
} while (cursor);
|
|
@@ -513,7 +581,11 @@ class ZimmerStack {
|
|
|
513
581
|
sandbox = {
|
|
514
582
|
bookings: {
|
|
515
583
|
list: (options) => this.request("GET /sandbox/bookings", options),
|
|
516
|
-
/**
|
|
584
|
+
/**
|
|
585
|
+
* Pretend an OTA booked: the booking, the availability moved down, and the real webhook to your endpoint.
|
|
586
|
+
* With `otaName: "Website"` it pretends a guest booked on the hotel's own website instead, and the webhook
|
|
587
|
+
* is `direct.booking.created`.
|
|
588
|
+
*/
|
|
517
589
|
create: (body, options) => this.request("POST /sandbox/bookings", { body, ...options }),
|
|
518
590
|
cancel: (bookingId, options) => this.request("POST /sandbox/bookings/{bookingId}/cancel", { path: { bookingId }, ...options }),
|
|
519
591
|
modify: (bookingId, body, options) => this.request("POST /sandbox/bookings/{bookingId}/modify", { path: { bookingId }, body, ...options }),
|
package/dist/cjs/generated.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/** This package's version, sent as the user agent so ZimmerStack can tell which client a request came from. */
|
|
2
|
-
export declare const SDK_VERSION = "0.
|
|
2
|
+
export declare const SDK_VERSION = "0.3.0";
|
|
3
3
|
/** Where the API lives. The key is sent nowhere else. */
|
|
4
4
|
export declare const API_ORIGIN = "https://api.zimmerstack.com";
|
|
5
5
|
export declare const API_PREFIX = "/api/v1/connect-api/v1";
|
|
@@ -28,7 +28,7 @@ export declare const LIMITS: {
|
|
|
28
28
|
export declare const ERROR_CODES: readonly ["API_KEY_INVALID", "API_KEY_REVOKED", "API_KEY_EXPIRED", "CONNECT_API_NOT_CONFIGURED", "IP_NOT_ALLOWED", "SCOPE_MISSING", "PROPERTY_UNAVAILABLE", "CHANNEL_MANAGER_DISABLED", "PMS_NOT_AVAILABLE", "VALIDATION", "RANGE_INVALID", "HORIZON", "TOO_MANY_UPDATES", "TOO_MANY_CELLS", "UNKNOWN_ROOM_TYPE", "UNKNOWN_RATE_PLAN", "CURRENCY_MISMATCH", "RATE_LIMITED", "NOTHING_ACCEPTED", "BATCH_NOT_FOUND", "IDEMPOTENCY_KEY_INVALID", "IDEMPOTENCY_KEY_REUSED", "IDEMPOTENCY_IN_FLIGHT", "STAY_INVALID", "UNKNOWN_ROOM_TYPE_FOR_PLAN", "OCCUPANCY_EXCEEDED", "NO_AVAILABILITY", "EXTERNAL_REFERENCE_REUSED", "PAYMENT_NOT_ALLOWED", "PAYMENT_EXCEEDS_TOTAL", "BOOKING_NOT_FOUND", "BOOKING_NOT_CANCELLABLE", "MODULE_NOT_ENTITLED", "SANDBOX_ONLY", "ROOM_TYPE_NOT_FOUND", "RATE_PLAN_NOT_FOUND", "CATALOG_CONFLICT", "CATALOG_BUSY", "CHANNEL_MANAGER_ERROR", "PROPERTY_REQUIRED", "PROPERTY_NOT_FOUND", "ARI_NOT_AUTHORITATIVE", "ROUTE_NOT_FOUND", "PAYLOAD_TOO_LARGE", "AUTH_BACKEND_UNAVAILABLE", "BOOKING_NOT_MODIFIABLE", "SANDBOX_NOT_FOUND", "SANDBOX_INCOMPLETE", "WRITES_FROZEN", "WRITES_SUSPENDED", "SHIELD_UNAVAILABLE", "CATALOG_LIMIT_REACHED", "TOO_MANY_NEW_ENTITIES", "RATE_OUT_OF_BAND", "CHANNEL_NOT_FOUND", "CHANNEL_SHARED", "MODIFIER_OUT_OF_BAND"];
|
|
29
29
|
export type ErrorCode = (typeof ERROR_CODES)[number];
|
|
30
30
|
/** What a key may do. The hotel's owner (or, for a vendor's key, the vendor) chose them when the key was made. */
|
|
31
|
-
export declare const SCOPES: readonly ["ari:read", "ari:write", "catalog:write", "channel-modifiers:write", "channel-bookings:read", "bookings:read", "bookings:write", "bookings:payments"];
|
|
31
|
+
export declare const SCOPES: readonly ["ari:read", "ari:write", "catalog:write", "channel-modifiers:write", "channel-bookings:read", "direct-bookings:read", "bookings:read", "bookings:write", "bookings:payments"];
|
|
32
32
|
export type Scope = (typeof SCOPES)[number];
|
|
33
33
|
/** When a channel's price modifier takes effect. Show it where a person saves one. */
|
|
34
34
|
export declare const MODIFIER_TAKES_EFFECT = "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.";
|
|
@@ -166,7 +166,7 @@ export interface RoomTypesUpsert {
|
|
|
166
166
|
ref: string;
|
|
167
167
|
/** Shown to the owner and sent to the channel manager as the title */
|
|
168
168
|
name: string;
|
|
169
|
-
/** Sellable rooms of this type.
|
|
169
|
+
/** Sellable rooms of this type. On a channel-manager-only hotel a later change is written too, to the channel manager first (its count caps what the channels sell); a count below the rooms holding upcoming stays is refused. On a hotel that runs our PMS the count comes from its room list and a different value is not written (the answer's notice says so) */
|
|
170
170
|
roomCount: number;
|
|
171
171
|
/** Most adults one room takes */
|
|
172
172
|
adults: number;
|
|
@@ -585,9 +585,9 @@ export interface SandboxBookingCreate {
|
|
|
585
585
|
adults?: number;
|
|
586
586
|
/** The guest's name; default a fictional one */
|
|
587
587
|
guestName?: string;
|
|
588
|
-
/** The channel the booking pretends to arrive from; default Booking.com */
|
|
589
|
-
otaName?: "Booking.com" | "Expedia" | "Agoda" | "Airbnb" | "MakeMyTrip" | "Goibibo";
|
|
590
|
-
/** true = the channel collected the money, so totalPaid equals the total; default false (pay at the property) */
|
|
588
|
+
/** The channel the booking pretends to arrive from; default Booking.com. "Website" simulates a booking on the hotel's own website (our booking engine): it sends direct.booking.created and is listed by GET /direct-bookings, not GET /channel-bookings */
|
|
589
|
+
otaName?: "Booking.com" | "Expedia" | "Agoda" | "Airbnb" | "MakeMyTrip" | "Goibibo" | "Website";
|
|
590
|
+
/** true = the channel collected the money (for Website: the guest paid online), so totalPaid equals the total; default false (pay at the property) */
|
|
591
591
|
paidByOta?: boolean;
|
|
592
592
|
}
|
|
593
593
|
export interface SandboxBookingModify {
|
|
@@ -872,13 +872,13 @@ export interface SandboxBooking {
|
|
|
872
872
|
createdAt: string;
|
|
873
873
|
/** What this call put on the wire for the sandbox's webhook endpoints */
|
|
874
874
|
webhook: {
|
|
875
|
-
eventType: "channel.booking.created" | "channel.booking.modified" | "channel.booking.cancelled";
|
|
875
|
+
eventType: "channel.booking.created" | "channel.booking.modified" | "channel.booking.cancelled" | "direct.booking.created" | "direct.booking.cancelled";
|
|
876
876
|
/** The event is in the outbox; every active endpoint on the sandbox receives it within seconds */
|
|
877
877
|
queued: boolean;
|
|
878
878
|
};
|
|
879
879
|
}
|
|
880
880
|
export interface SandboxBookingsList {
|
|
881
|
-
/** Simulated
|
|
881
|
+
/** Simulated bookings on the sandbox (OTA and website), newest first */
|
|
882
882
|
bookings: Array<{
|
|
883
883
|
/** The PMS booking id, the one the webhook carries */
|
|
884
884
|
bookingId: number;
|
|
@@ -905,7 +905,7 @@ export interface SandboxBookingsList {
|
|
|
905
905
|
createdAt: string;
|
|
906
906
|
/** What this call put on the wire for the sandbox's webhook endpoints */
|
|
907
907
|
webhook: {
|
|
908
|
-
eventType: "channel.booking.created" | "channel.booking.modified" | "channel.booking.cancelled";
|
|
908
|
+
eventType: "channel.booking.created" | "channel.booking.modified" | "channel.booking.cancelled" | "direct.booking.created" | "direct.booking.cancelled";
|
|
909
909
|
/** The event is in the outbox; every active endpoint on the sandbox receives it within seconds */
|
|
910
910
|
queued: boolean;
|
|
911
911
|
};
|
|
@@ -1103,6 +1103,27 @@ export interface Operations {
|
|
|
1103
1103
|
body: undefined;
|
|
1104
1104
|
response: ChannelBooking;
|
|
1105
1105
|
};
|
|
1106
|
+
/** The bookings guests made on the hotel's own website, in the webhook's shape */
|
|
1107
|
+
"GET /direct-bookings": {
|
|
1108
|
+
path: undefined;
|
|
1109
|
+
query: {
|
|
1110
|
+
since?: string;
|
|
1111
|
+
status?: "CONFIRMED" | "CANCELLED";
|
|
1112
|
+
limit?: number;
|
|
1113
|
+
cursor?: string;
|
|
1114
|
+
};
|
|
1115
|
+
body: undefined;
|
|
1116
|
+
response: ChannelBookingsList;
|
|
1117
|
+
};
|
|
1118
|
+
/** One website booking, the webhook's shape */
|
|
1119
|
+
"GET /direct-bookings/{bookingId}": {
|
|
1120
|
+
path: {
|
|
1121
|
+
bookingId: string | number;
|
|
1122
|
+
};
|
|
1123
|
+
query: undefined;
|
|
1124
|
+
body: undefined;
|
|
1125
|
+
response: ChannelBooking;
|
|
1126
|
+
};
|
|
1106
1127
|
/** Simulated OTA bookings on the sandbox, newest first */
|
|
1107
1128
|
"GET /sandbox/bookings": {
|
|
1108
1129
|
path: undefined;
|
package/dist/cjs/generated.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
5
|
exports.OPERATIONS = exports.MODIFIER_TAKES_EFFECT = exports.SCOPES = exports.ERROR_CODES = exports.LIMITS = exports.PROPERTY_HEADER = exports.IDEMPOTENCY_HEADER = exports.API_PREFIX = exports.API_ORIGIN = exports.SDK_VERSION = void 0;
|
|
6
6
|
/** This package's version, sent as the user agent so ZimmerStack can tell which client a request came from. */
|
|
7
|
-
exports.SDK_VERSION = "0.
|
|
7
|
+
exports.SDK_VERSION = "0.3.0";
|
|
8
8
|
/** Where the API lives. The key is sent nowhere else. */
|
|
9
9
|
exports.API_ORIGIN = "https://api.zimmerstack.com";
|
|
10
10
|
exports.API_PREFIX = "/api/v1/connect-api/v1";
|
|
@@ -96,6 +96,7 @@ exports.SCOPES = [
|
|
|
96
96
|
"catalog:write",
|
|
97
97
|
"channel-modifiers:write",
|
|
98
98
|
"channel-bookings:read",
|
|
99
|
+
"direct-bookings:read",
|
|
99
100
|
"bookings:read",
|
|
100
101
|
"bookings:write",
|
|
101
102
|
"bookings:payments"
|
|
@@ -127,6 +128,8 @@ exports.OPERATIONS = {
|
|
|
127
128
|
"POST /rates/resend": { idempotent: true, bodyRequired: false },
|
|
128
129
|
"GET /channel-bookings": { idempotent: false, bodyRequired: false },
|
|
129
130
|
"GET /channel-bookings/{bookingId}": { idempotent: false, bodyRequired: false },
|
|
131
|
+
"GET /direct-bookings": { idempotent: false, bodyRequired: false },
|
|
132
|
+
"GET /direct-bookings/{bookingId}": { idempotent: false, bodyRequired: false },
|
|
130
133
|
"GET /sandbox/bookings": { idempotent: false, bodyRequired: false },
|
|
131
134
|
"POST /sandbox/bookings": { idempotent: true, bodyRequired: true },
|
|
132
135
|
"POST /sandbox/bookings/{bookingId}/cancel": { idempotent: false, bodyRequired: false },
|
package/dist/cjs/index.d.ts
CHANGED
|
@@ -10,7 +10,7 @@ export { ZimmerStackError, ZimmerStackUsageError } from "./errors.js";
|
|
|
10
10
|
export type { LocalErrorCode } from "./errors.js";
|
|
11
11
|
export { addDays, buildGrid, channelPrice, chunk, eachDate, toRanges } from "./grid.js";
|
|
12
12
|
export type { Grid, GridEdits, ModifierStep, Range, Restrictions } from "./grid.js";
|
|
13
|
-
export { verifyWebhook, ZimmerStackWebhookError } from "./webhooks.js";
|
|
14
|
-
export type { WebhookEvent } from "./webhooks.js";
|
|
13
|
+
export { BOOKING_EVENT_TYPES, OTA_BOOKING_EVENT_TYPES, WEBSITE_BOOKING_EVENT_TYPES, isOtaBookingEvent, isWebsiteBookingEvent, verifyWebhook, ZimmerStackWebhookError } from "./webhooks.js";
|
|
14
|
+
export type { BookingEvent, BookingEventType, OtaBookingEvent, OtaBookingEventType, WebhookEvent, WebhookEventType, WebsiteBookingEvent, WebsiteBookingEventType } from "./webhooks.js";
|
|
15
15
|
export { ERROR_CODES, LIMITS, MODIFIER_TAKES_EFFECT, SCOPES, SDK_VERSION } from "./generated.js";
|
|
16
16
|
export type * from "./generated.js";
|
package/dist/cjs/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SDK_VERSION = exports.SCOPES = exports.MODIFIER_TAKES_EFFECT = exports.LIMITS = exports.ERROR_CODES = exports.ZimmerStackWebhookError = exports.verifyWebhook = exports.toRanges = exports.eachDate = exports.chunk = exports.channelPrice = exports.buildGrid = exports.addDays = exports.ZimmerStackUsageError = exports.ZimmerStackError = exports.ZimmerStack = void 0;
|
|
3
|
+
exports.SDK_VERSION = exports.SCOPES = exports.MODIFIER_TAKES_EFFECT = exports.LIMITS = exports.ERROR_CODES = exports.ZimmerStackWebhookError = exports.verifyWebhook = exports.isWebsiteBookingEvent = exports.isOtaBookingEvent = exports.WEBSITE_BOOKING_EVENT_TYPES = exports.OTA_BOOKING_EVENT_TYPES = exports.BOOKING_EVENT_TYPES = exports.toRanges = exports.eachDate = exports.chunk = exports.channelPrice = exports.buildGrid = exports.addDays = exports.ZimmerStackUsageError = exports.ZimmerStackError = exports.ZimmerStack = void 0;
|
|
4
4
|
/**
|
|
5
5
|
* @zimmerstack/connect: the ZimmerStack Connect API from your server.
|
|
6
6
|
*
|
|
@@ -20,6 +20,11 @@ Object.defineProperty(exports, "chunk", { enumerable: true, get: function () { r
|
|
|
20
20
|
Object.defineProperty(exports, "eachDate", { enumerable: true, get: function () { return grid_ts_1.eachDate; } });
|
|
21
21
|
Object.defineProperty(exports, "toRanges", { enumerable: true, get: function () { return grid_ts_1.toRanges; } });
|
|
22
22
|
var webhooks_ts_1 = require("./webhooks.js");
|
|
23
|
+
Object.defineProperty(exports, "BOOKING_EVENT_TYPES", { enumerable: true, get: function () { return webhooks_ts_1.BOOKING_EVENT_TYPES; } });
|
|
24
|
+
Object.defineProperty(exports, "OTA_BOOKING_EVENT_TYPES", { enumerable: true, get: function () { return webhooks_ts_1.OTA_BOOKING_EVENT_TYPES; } });
|
|
25
|
+
Object.defineProperty(exports, "WEBSITE_BOOKING_EVENT_TYPES", { enumerable: true, get: function () { return webhooks_ts_1.WEBSITE_BOOKING_EVENT_TYPES; } });
|
|
26
|
+
Object.defineProperty(exports, "isOtaBookingEvent", { enumerable: true, get: function () { return webhooks_ts_1.isOtaBookingEvent; } });
|
|
27
|
+
Object.defineProperty(exports, "isWebsiteBookingEvent", { enumerable: true, get: function () { return webhooks_ts_1.isWebsiteBookingEvent; } });
|
|
23
28
|
Object.defineProperty(exports, "verifyWebhook", { enumerable: true, get: function () { return webhooks_ts_1.verifyWebhook; } });
|
|
24
29
|
Object.defineProperty(exports, "ZimmerStackWebhookError", { enumerable: true, get: function () { return webhooks_ts_1.ZimmerStackWebhookError; } });
|
|
25
30
|
var generated_ts_1 = require("./generated.js");
|
package/dist/cjs/webhooks.d.ts
CHANGED
|
@@ -3,11 +3,30 @@ import type { ChannelBooking } from "./generated.js";
|
|
|
3
3
|
* Verifying a webhook ZimmerStack sent you (Standard Webhooks: the `webhook-id`, `webhook-timestamp` and
|
|
4
4
|
* `webhook-signature` headers). Uses Web Crypto, so it runs on Node and on edge runtimes alike.
|
|
5
5
|
*/
|
|
6
|
+
/** An OTA booking arrived, changed or was cancelled (through the channel manager). */
|
|
7
|
+
export declare const OTA_BOOKING_EVENT_TYPES: readonly ["channel.booking.created", "channel.booking.modified", "channel.booking.cancelled"];
|
|
8
|
+
/**
|
|
9
|
+
* A guest booked, or cancelled, on the hotel's own website through ZimmerStack's booking engine. The same
|
|
10
|
+
* booking object as the OTA events, in a family of its own: an endpoint receives these only when it lists
|
|
11
|
+
* the two types. There is no modified event.
|
|
12
|
+
*/
|
|
13
|
+
export declare const WEBSITE_BOOKING_EVENT_TYPES: readonly ["direct.booking.created", "direct.booking.cancelled"];
|
|
14
|
+
/** Every event whose `data.booking` is a booking, of either family. */
|
|
15
|
+
export declare const BOOKING_EVENT_TYPES: readonly ["channel.booking.created", "channel.booking.modified", "channel.booking.cancelled", "direct.booking.created", "direct.booking.cancelled"];
|
|
16
|
+
export type OtaBookingEventType = (typeof OTA_BOOKING_EVENT_TYPES)[number];
|
|
17
|
+
export type WebsiteBookingEventType = (typeof WEBSITE_BOOKING_EVENT_TYPES)[number];
|
|
18
|
+
export type BookingEventType = (typeof BOOKING_EVENT_TYPES)[number];
|
|
19
|
+
/** Every type an endpoint can receive. A newer API may add more: `WebhookEvent.type` stays a string. */
|
|
20
|
+
export type WebhookEventType = BookingEventType | "channel.sync.alert" | "channel.sync.recovered" | "zimmerstack.ping";
|
|
6
21
|
/** What every delivery carries. Deliveries are at-least-once: dedupe on `id`, order on `occurredAt`. */
|
|
7
22
|
export interface WebhookEvent {
|
|
8
23
|
/** "evt_<uuid>", the same on every retry and on every endpoint. */
|
|
9
24
|
id: string;
|
|
10
|
-
/**
|
|
25
|
+
/**
|
|
26
|
+
* channel.booking.created · channel.booking.modified · channel.booking.cancelled (an OTA booking) ·
|
|
27
|
+
* direct.booking.created · direct.booking.cancelled (a booking on the hotel's own website) ·
|
|
28
|
+
* channel.sync.* · zimmerstack.ping. Narrow it with `isOtaBookingEvent` and `isWebsiteBookingEvent`.
|
|
29
|
+
*/
|
|
11
30
|
type: string;
|
|
12
31
|
apiVersion: string;
|
|
13
32
|
occurredAt: string;
|
|
@@ -30,6 +49,29 @@ export interface WebhookEvent {
|
|
|
30
49
|
previous?: Record<string, unknown> | null;
|
|
31
50
|
truncated?: boolean;
|
|
32
51
|
}
|
|
52
|
+
/** An event whose `data.booking` is there: of either booking family. */
|
|
53
|
+
export type BookingEvent = WebhookEvent & {
|
|
54
|
+
type: BookingEventType;
|
|
55
|
+
data: {
|
|
56
|
+
booking: ChannelBooking;
|
|
57
|
+
[key: string]: unknown;
|
|
58
|
+
};
|
|
59
|
+
};
|
|
60
|
+
/** A booking a guest made on the hotel's own website. `finance` is null and `changes` and `previous` always are. */
|
|
61
|
+
export type WebsiteBookingEvent = BookingEvent & {
|
|
62
|
+
type: WebsiteBookingEventType;
|
|
63
|
+
};
|
|
64
|
+
/** A booking an OTA sent. */
|
|
65
|
+
export type OtaBookingEvent = BookingEvent & {
|
|
66
|
+
type: OtaBookingEventType;
|
|
67
|
+
};
|
|
68
|
+
/**
|
|
69
|
+
* True for `direct.booking.created` and `direct.booking.cancelled`: a booking made on the hotel's own
|
|
70
|
+
* website. A PMS that pushes room counts must put it in its own calendar before its next push.
|
|
71
|
+
*/
|
|
72
|
+
export declare function isWebsiteBookingEvent(event: WebhookEvent): event is WebsiteBookingEvent;
|
|
73
|
+
/** True for `channel.booking.created`, `.modified` and `.cancelled`: a booking an OTA sent. */
|
|
74
|
+
export declare function isOtaBookingEvent(event: WebhookEvent): event is OtaBookingEvent;
|
|
33
75
|
export declare class ZimmerStackWebhookError extends Error {
|
|
34
76
|
/** Why the delivery was refused. Answer 400 and do not act on the body. */
|
|
35
77
|
readonly reason: "missing_headers" | "stale_timestamp" | "bad_signature" | "bad_body";
|
package/dist/cjs/webhooks.js
CHANGED
|
@@ -1,7 +1,35 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ZimmerStackWebhookError = void 0;
|
|
3
|
+
exports.ZimmerStackWebhookError = exports.BOOKING_EVENT_TYPES = exports.WEBSITE_BOOKING_EVENT_TYPES = exports.OTA_BOOKING_EVENT_TYPES = void 0;
|
|
4
|
+
exports.isWebsiteBookingEvent = isWebsiteBookingEvent;
|
|
5
|
+
exports.isOtaBookingEvent = isOtaBookingEvent;
|
|
4
6
|
exports.verifyWebhook = verifyWebhook;
|
|
7
|
+
/**
|
|
8
|
+
* Verifying a webhook ZimmerStack sent you (Standard Webhooks: the `webhook-id`, `webhook-timestamp` and
|
|
9
|
+
* `webhook-signature` headers). Uses Web Crypto, so it runs on Node and on edge runtimes alike.
|
|
10
|
+
*/
|
|
11
|
+
/** An OTA booking arrived, changed or was cancelled (through the channel manager). */
|
|
12
|
+
exports.OTA_BOOKING_EVENT_TYPES = ["channel.booking.created", "channel.booking.modified", "channel.booking.cancelled"];
|
|
13
|
+
/**
|
|
14
|
+
* A guest booked, or cancelled, on the hotel's own website through ZimmerStack's booking engine. The same
|
|
15
|
+
* booking object as the OTA events, in a family of its own: an endpoint receives these only when it lists
|
|
16
|
+
* the two types. There is no modified event.
|
|
17
|
+
*/
|
|
18
|
+
exports.WEBSITE_BOOKING_EVENT_TYPES = ["direct.booking.created", "direct.booking.cancelled"];
|
|
19
|
+
/** Every event whose `data.booking` is a booking, of either family. */
|
|
20
|
+
exports.BOOKING_EVENT_TYPES = [...exports.OTA_BOOKING_EVENT_TYPES, ...exports.WEBSITE_BOOKING_EVENT_TYPES];
|
|
21
|
+
const isType = (list, event) => typeof event?.type === "string" && list.includes(event.type);
|
|
22
|
+
/**
|
|
23
|
+
* True for `direct.booking.created` and `direct.booking.cancelled`: a booking made on the hotel's own
|
|
24
|
+
* website. A PMS that pushes room counts must put it in its own calendar before its next push.
|
|
25
|
+
*/
|
|
26
|
+
function isWebsiteBookingEvent(event) {
|
|
27
|
+
return isType(exports.WEBSITE_BOOKING_EVENT_TYPES, event) && Boolean(event.data?.booking);
|
|
28
|
+
}
|
|
29
|
+
/** True for `channel.booking.created`, `.modified` and `.cancelled`: a booking an OTA sent. */
|
|
30
|
+
function isOtaBookingEvent(event) {
|
|
31
|
+
return isType(exports.OTA_BOOKING_EVENT_TYPES, event) && Boolean(event.data?.booking);
|
|
32
|
+
}
|
|
5
33
|
class ZimmerStackWebhookError extends Error {
|
|
6
34
|
/** Why the delivery was refused. Answer 400 and do not act on the body. */
|
|
7
35
|
reason;
|