@zimmerstack/connect 0.2.0 → 0.4.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 CHANGED
@@ -64,6 +64,28 @@ https://docs.zimmerstack.com/llms-full.txt
64
64
  - Keep the grid on the price before any modifier; show a channel's price beside it with
65
65
  `channelPrice(rate, steps)`.
66
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
+ - `zs.directBookings.cancel(bookingId, { refund, reason })` cancels a whole website booking that is
79
+ still UPCOMING, and moves the guest's money (scope `direct-bookings:cancel`, granted on its own).
80
+ `refund` is `"policy"` (the default: what the booking's own cancellation policy gives back, as if the
81
+ guest cancelled), `"full"` (everything paid online: the hotel is at fault, an overbooking) or
82
+ `"none"` (the hotel settles the money itself). Call it only from a person's own cancel button, with
83
+ the refund they chose on the screen; never from a loop, a sync job or a test against a live key.
84
+ Show `refund.amount` and `refund.status` from the answer. `BOOKING_NOT_CANCELLABLE` (checked in,
85
+ checked out, a no-show) goes to the hotel's desk; do not retry it. `replay: true` means it was
86
+ already cancelled and no money moved. Your own cancel comes back as `direct.booking.cancelled`
87
+ ("Cancelled by the hotel"): match it on the booking id and treat it as already applied.
88
+
67
89
  ## Errors
68
90
 
69
91
  ```ts
@@ -105,3 +127,5 @@ these tools.
105
127
  - [ ] Errors show `err.message` to the person and branch on `err.code`.
106
128
  - [ ] Tests run against a `zsk_test_` key or a fake `fetch`; none needs a live key.
107
129
  - [ ] Where a modifier is saved, the screen says when it takes effect, and the re-send is its own button.
130
+ - [ ] A PMS that pushes room counts applies every website booking to its own calendar before it pushes.
131
+ - [ ] A website booking is cancelled only from a person's own action, with the refund they chose.
package/README.md CHANGED
@@ -86,7 +86,9 @@ zs.channels.setModifier(channelId, steps)
86
86
 
87
87
  zs.bookings.create(…) / .get(id) / .list(…) / .cancel(id) // your own booking engine
88
88
  zs.channelBookings.list(…) / .get(id) / .all(…) // what the booking sites sent
89
- zs.sandbox.bookings.create(…) / .cancel(id) / .modify(id, …) // pretend an OTA booked (test keys)
89
+ zs.directBookings.list(…) / .get(id) / .all(…) // what guests booked on the hotel's own website
90
+ zs.directBookings.cancel(id, { refund }) // cancel one from your PMS, with its refund
91
+ zs.sandbox.bookings.create(…) / .cancel(id) / .modify(id, …) // pretend an OTA or the website booked (test keys)
90
92
 
91
93
  zs.request("GET /sync") // any operation of the contract by name, typed
92
94
  ```
@@ -160,13 +162,14 @@ loop of your own.
160
162
  ## Webhooks
161
163
 
162
164
  ```ts
163
- import { verifyWebhook } from "@zimmerstack/connect";
165
+ import { isOtaBookingEvent, isWebsiteBookingEvent, verifyWebhook } from "@zimmerstack/connect";
164
166
 
165
167
  export async function POST(request: Request) {
166
168
  // The body exactly as it arrived, before any JSON parsing.
167
169
  const event = await verifyWebhook(await request.text(), request.headers, process.env.ZIMMERSTACK_WEBHOOK_SECRET!);
168
170
  // Deliveries are at-least-once: remember event.id and skip one you have seen.
169
- if (event.type === "channel.booking.created") await save(event.data.booking);
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
170
173
  return new Response(null, { status: 204 });
171
174
  }
172
175
  ```
@@ -174,6 +177,45 @@ export async function POST(request: Request) {
174
177
  It throws `ZimmerStackWebhookError` for a delivery that is not ZimmerStack's or is older than five
175
178
  minutes: answer 400 and do not act on the body.
176
179
 
180
+ ## Bookings from the hotel's own website
181
+
182
+ A hotel that sells on its own website through ZimmerStack's booking engine, and keeps its own PMS,
183
+ gets those bookings in a family of their own: the webhooks `direct.booking.created` and
184
+ `direct.booking.cancelled` (the endpoint must list both types; one registered earlier receives none
185
+ until its owner ticks them), and `zs.directBookings` for the pull (scope `direct-bookings:read`). The
186
+ booking object is the one OTA bookings use. `channel.otaName` is `"Website"`, `finance` is null, and
187
+ `amounts.paid` is what the guest paid online. There is no modified event.
188
+
189
+ **Apply a website booking to your own calendar before your next push of room counts.** The booking
190
+ takes one room off the count the channels hold at once; a push of the old absolute count would put it
191
+ back on sale. Read `zs.directBookings.all` before a full push:
192
+
193
+ ```ts
194
+ for await (const booking of zs.directBookings.all({ since: lastSeen })) applyToMyCalendar(booking);
195
+ await zs.grid.save(edits); // only now
196
+ ```
197
+
198
+ A guest cancels on the booking page, or the hotel cancels in ZimmerStack. From 0.4.0 your PMS can
199
+ cancel one too, and say what the guest gets back (scope `direct-bookings:cancel`, granted on its own):
200
+
201
+ ```ts
202
+ const { refund, replay } = await zs.directBookings.cancel(bookingId, { refund: "policy", reason: "Guest phoned to cancel" });
203
+ // refund.amount in major units; refund.status NONE, PENDING, PROCESSED or MANUAL
204
+ ```
205
+
206
+ `refund` is `"policy"` (the default: what the booking's own cancellation policy gives back now, as if the
207
+ guest cancelled on the booking page; for a guest who asks the hotel to cancel), `"full"` (everything
208
+ the guest paid online; when the hotel is at fault, such as an overbooking) or `"none"` (the hotel
209
+ settles the money another way). The refund goes back to the guest's online payment, never more than
210
+ it. A checked-in, checked-out or no-show booking is `BOOKING_NOT_CANCELLABLE`; one already cancelled
211
+ answers `replay: true` and moves no money. Your own cancel comes back as `direct.booking.cancelled`
212
+ ("Cancelled by the hotel"): match it on the booking id and treat it as already applied. Call it from
213
+ a person's own cancel button, never from a sync job.
214
+
215
+ To try it with a test key, `zs.sandbox.bookings.create({ …, otaName: "Website" })`, then cancel that
216
+ booking with `zs.directBookings.cancel`: the nights come back and no money moves.
217
+ Guide: <https://docs.zimmerstack.com/website-bookings#cancel>
218
+
177
219
  ## Options
178
220
 
179
221
  ```ts
@@ -237,4 +279,5 @@ real hotel through it. Without a key the rules and the reference still work.
237
279
  - Guides and reference: <https://docs.zimmerstack.com>
238
280
  - Build a rate grid: <https://docs.zimmerstack.com/rate-grid>
239
281
  - Prices per channel: <https://docs.zimmerstack.com/per-ota>
282
+ - Bookings from the hotel's own website: <https://docs.zimmerstack.com/website-bookings>
240
283
  - Limits: <https://docs.zimmerstack.com/limits> · Errors: <https://docs.zimmerstack.com/errors>
@@ -1,4 +1,4 @@
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";
1
+ import { type AvailabilityWrite, type BatchStatus, type Booking, type BookingCancel, type BookingCreate, type Catalog, type ChannelBooking, type DirectBookingCancel, type DirectBookingCancelResult, 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
2
  import { type Grid, type GridEdits, type ModifierStep } from "./grid.js";
3
3
  export interface ZimmerStackOptions {
4
4
  /**
@@ -231,10 +231,52 @@ 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
+ /**
250
+ * Cancel a whole website booking that is still UPCOMING, and say what the guest gets back. Scope
251
+ * `direct-bookings:cancel`, granted on its own and never by default.
252
+ *
253
+ * `refund`: `"policy"` (the default) is what the booking's own cancellation policy gives back now, as
254
+ * if the guest cancelled on the booking page; `"full"` is everything the guest paid online (the hotel
255
+ * is at fault: an overbooking); `"none"` moves no money (the hotel settles it another way). The refund
256
+ * goes back to the guest's online payment and never exceeds it. The answer's `refund` says how much
257
+ * and where it stands (NONE, PENDING, PROCESSED, MANUAL).
258
+ *
259
+ * IT MOVES A GUEST'S MONEY. Call it from a person's own cancel button, with the refund they chose;
260
+ * never from a loop, a sync job or a test against a live key. A booking already cancelled answers
261
+ * `replay: true` and moves no money; checked in, checked out or a no-show is BOOKING_NOT_CANCELLABLE.
262
+ * Your own cancel comes back as `direct.booking.cancelled` ("Cancelled by the hotel"): treat it as
263
+ * already applied. The call carries an idempotency key (yours, or one the client makes) and a retry
264
+ * after a network failure reuses it, so a cancel never lands twice; pass your own `idempotencyKey`
265
+ * when a retry may come from another process.
266
+ *
267
+ * @example
268
+ * const { refund } = await zs.directBookings.cancel(bookingId, { refund: "full", reason: "Overbooked" });
269
+ */
270
+ cancel: (bookingId: number, body?: DirectBookingCancel, options?: WriteOptions) => Promise<DirectBookingCancelResult>;
271
+ };
234
272
  readonly sandbox: {
235
273
  bookings: {
236
274
  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. */
275
+ /**
276
+ * Pretend an OTA booked: the booking, the availability moved down, and the real webhook to your endpoint.
277
+ * With `otaName: "Website"` it pretends a guest booked on the hotel's own website instead, and the webhook
278
+ * is `direct.booking.created`.
279
+ */
238
280
  create: (body: SandboxBookingCreate, options?: WriteOptions) => Promise<import("./generated.js").SandboxBooking>;
239
281
  cancel: (bookingId: number, options?: ReadOptions) => Promise<import("./generated.js").SandboxBooking>;
240
282
  modify: (bookingId: number, body: SandboxBookingModify, options?: ReadOptions) => Promise<import("./generated.js").SandboxBooking>;
@@ -549,12 +549,52 @@ class ZimmerStack {
549
549
  * @example
550
550
  * for await (const booking of zs.channelBookings.all({ since: lastSeen })) save(booking);
551
551
  */
552
- all: (query, options) => this.#allChannelBookings(query, options),
552
+ all: (query, options) => this.#allPages((cursor) => this.channelBookings.list({ limit: 100, ...query, cursor }, options)),
553
553
  };
554
- async *#allChannelBookings(query, options) {
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)),
570
+ /**
571
+ * Cancel a whole website booking that is still UPCOMING, and say what the guest gets back. Scope
572
+ * `direct-bookings:cancel`, granted on its own and never by default.
573
+ *
574
+ * `refund`: `"policy"` (the default) is what the booking's own cancellation policy gives back now, as
575
+ * if the guest cancelled on the booking page; `"full"` is everything the guest paid online (the hotel
576
+ * is at fault: an overbooking); `"none"` moves no money (the hotel settles it another way). The refund
577
+ * goes back to the guest's online payment and never exceeds it. The answer's `refund` says how much
578
+ * and where it stands (NONE, PENDING, PROCESSED, MANUAL).
579
+ *
580
+ * IT MOVES A GUEST'S MONEY. Call it from a person's own cancel button, with the refund they chose;
581
+ * never from a loop, a sync job or a test against a live key. A booking already cancelled answers
582
+ * `replay: true` and moves no money; checked in, checked out or a no-show is BOOKING_NOT_CANCELLABLE.
583
+ * Your own cancel comes back as `direct.booking.cancelled` ("Cancelled by the hotel"): treat it as
584
+ * already applied. The call carries an idempotency key (yours, or one the client makes) and a retry
585
+ * after a network failure reuses it, so a cancel never lands twice; pass your own `idempotencyKey`
586
+ * when a retry may come from another process.
587
+ *
588
+ * @example
589
+ * const { refund } = await zs.directBookings.cancel(bookingId, { refund: "full", reason: "Overbooked" });
590
+ */
591
+ cancel: (bookingId, body = {}, options) => this.request("POST /direct-bookings/{bookingId}/cancel", { path: { bookingId }, body, ...options }),
592
+ };
593
+ /** Follow a booking list's `nextCursor` to its last page. */
594
+ async *#allPages(read) {
555
595
  let cursor;
556
596
  do {
557
- const page = await this.channelBookings.list({ limit: 100, ...query, cursor }, options);
597
+ const page = await read(cursor);
558
598
  yield* page.items;
559
599
  cursor = page.nextCursor ?? undefined;
560
600
  } while (cursor);
@@ -563,7 +603,11 @@ class ZimmerStack {
563
603
  sandbox = {
564
604
  bookings: {
565
605
  list: (options) => this.request("GET /sandbox/bookings", options),
566
- /** Pretend an OTA booked: the booking, the availability moved down, and the real webhook to your endpoint. */
606
+ /**
607
+ * Pretend an OTA booked: the booking, the availability moved down, and the real webhook to your endpoint.
608
+ * With `otaName: "Website"` it pretends a guest booked on the hotel's own website instead, and the webhook
609
+ * is `direct.booking.created`.
610
+ */
567
611
  create: (body, options) => this.request("POST /sandbox/bookings", { body, ...options }),
568
612
  cancel: (bookingId, options) => this.request("POST /sandbox/bookings/{bookingId}/cancel", { path: { bookingId }, ...options }),
569
613
  modify: (bookingId, body, options) => this.request("POST /sandbox/bookings/{bookingId}/modify", { path: { bookingId }, body, ...options }),
@@ -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.0";
2
+ export declare const SDK_VERSION = "0.4.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";
@@ -21,6 +21,8 @@ export declare const LIMITS: {
21
21
  readonly bookingsPerMinute: 20;
22
22
  readonly propertyBookingsPerMinute: 40;
23
23
  readonly propertyBookingsPerDay: 500;
24
+ readonly directCancelsPerMinute: 10;
25
+ readonly propertyDirectCancelsPerDay: 50;
24
26
  readonly companyRequestsPerMinute: 1200;
25
27
  readonly maxNightsPerBooking: 90;
26
28
  };
@@ -28,7 +30,7 @@ export declare const LIMITS: {
28
30
  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
31
  export type ErrorCode = (typeof ERROR_CODES)[number];
30
32
  /** 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"];
33
+ export declare const SCOPES: readonly ["ari:read", "ari:write", "catalog:write", "channel-modifiers:write", "channel-bookings:read", "direct-bookings:read", "direct-bookings:cancel", "bookings:read", "bookings:write", "bookings:payments"];
32
34
  export type Scope = (typeof SCOPES)[number];
33
35
  /** When a channel's price modifier takes effect. Show it where a person saves one. */
34
36
  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.";
@@ -585,9 +587,9 @@ export interface SandboxBookingCreate {
585
587
  adults?: number;
586
588
  /** The guest's name; default a fictional one */
587
589
  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) */
590
+ /** 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 */
591
+ otaName?: "Booking.com" | "Expedia" | "Agoda" | "Airbnb" | "MakeMyTrip" | "Goibibo" | "Website";
592
+ /** true = the channel collected the money (for Website: the guest paid online), so totalPaid equals the total; default false (pay at the property) */
591
593
  paidByOta?: boolean;
592
594
  }
593
595
  export interface SandboxBookingModify {
@@ -846,6 +848,96 @@ export interface ChannelBooking {
846
848
  createdAt: string;
847
849
  updatedAt: string;
848
850
  }
851
+ export interface DirectBookingCancel {
852
+ /** policy (the default): what the booking's own cancellation policy gives back now, the same as the guest cancelling on the booking page. full: everything the guest paid online. none: nothing; the hotel settles any money itself. */
853
+ refund?: "policy" | "full" | "none";
854
+ /** Why; kept on the booking's activity log in ZimmerStack */
855
+ reason?: string;
856
+ }
857
+ export interface DirectBookingCancelResult {
858
+ /** The booking after the cancel, the webhook's shape: status CANCELLED, every room CANCELLED */
859
+ booking: {
860
+ id: number;
861
+ reference: string;
862
+ status: "CONFIRMED" | "CANCELLED";
863
+ stayStatus: string;
864
+ channel: {
865
+ otaName: string;
866
+ otaReservationCode: string;
867
+ source: string;
868
+ sourceGroup: string;
869
+ };
870
+ stay: {
871
+ checkIn: string;
872
+ checkOut: string;
873
+ nights: number;
874
+ dayUse: boolean;
875
+ };
876
+ guest: {
877
+ fullName: string;
878
+ firstName: string | null;
879
+ lastName: string | null;
880
+ phone?: string | null;
881
+ email?: string | null;
882
+ country: string | null;
883
+ language: string | null;
884
+ };
885
+ guestNotes: string | null;
886
+ occupancy: {
887
+ adults: number;
888
+ children: number;
889
+ };
890
+ rooms: Array<{
891
+ roomTypeId: number;
892
+ roomTypeName: string;
893
+ ratePlanId?: number | null;
894
+ mealPlan: "EP" | "CP" | "MAP" | "AP";
895
+ adults: number;
896
+ children: number;
897
+ checkIn: string;
898
+ checkOut: string;
899
+ nights: number;
900
+ dayUse: boolean;
901
+ ratePerNight: number;
902
+ amount: number;
903
+ status: string;
904
+ }>;
905
+ amounts: {
906
+ currency: string;
907
+ total: number;
908
+ paid: number;
909
+ balanceDue: number;
910
+ paymentCollect: "ota" | "property" | "unknown";
911
+ };
912
+ finance: {
913
+ otaName: string;
914
+ amountBasis: string;
915
+ currency: string | null;
916
+ grossAmount: number | null;
917
+ commissionAmount: number | null;
918
+ taxAmount: number | null;
919
+ netPayoutAmount: number | null;
920
+ } | null;
921
+ cancellation: {
922
+ at: string;
923
+ reason: string | null;
924
+ } | null;
925
+ createdAt: string;
926
+ updatedAt: string;
927
+ };
928
+ refund: {
929
+ /** The refund this call asked for; null on a replay */
930
+ requested: "policy" | "full" | "none" | null;
931
+ /** What the guest gets back, in currency's major units (1998.5 = ₹1,998.50); 0 when nothing is owed */
932
+ amount: number;
933
+ /** ISO 4217, the property's currency */
934
+ currency: string;
935
+ /** NONE: nothing owed. PROCESSED: the payment gateway accepted the refund. PENDING: the refund is recorded and on its way (the gateway is processing it, or ZimmerStack issues it by hand). MANUAL: money is owed but there is no online payment to refund against; the hotel settles it. */
936
+ status: "NONE" | "PENDING" | "PROCESSED" | "MANUAL";
937
+ };
938
+ /** true: the booking was already cancelled; nothing changed and no money moved */
939
+ replay: boolean;
940
+ }
849
941
  export interface SandboxBooking {
850
942
  /** The PMS booking id, the one the webhook carries */
851
943
  bookingId: number;
@@ -854,6 +946,7 @@ export interface SandboxBooking {
854
946
  /** The pretend channel-side id */
855
947
  channelBookingId: string;
856
948
  otaName: string;
949
+ /** The stay's state. GET /channel-bookings reads the same booking as status CONFIRMED (or CANCELLED) with stayStatus UPCOMING */
857
950
  status: "UPCOMING" | "CANCELLED";
858
951
  guestName: string;
859
952
  checkIn: string;
@@ -861,9 +954,9 @@ export interface SandboxBooking {
861
954
  nights: number;
862
955
  rooms: number;
863
956
  roomTypeId: number;
864
- /** Major units, per room per night */
957
+ /** Major units, per room per night: the average when the nights differ. Each night is priced from the sandbox's own record, what GET /rates gives for the room type's first rate plan */
865
958
  nightlyRate: number;
866
- /** Major units */
959
+ /** Major units: every night's price × rooms */
867
960
  total: number;
868
961
  currency: string;
869
962
  paidByOta: boolean;
@@ -872,13 +965,13 @@ export interface SandboxBooking {
872
965
  createdAt: string;
873
966
  /** What this call put on the wire for the sandbox's webhook endpoints */
874
967
  webhook: {
875
- eventType: "channel.booking.created" | "channel.booking.modified" | "channel.booking.cancelled";
968
+ eventType: "channel.booking.created" | "channel.booking.modified" | "channel.booking.cancelled" | "direct.booking.created" | "direct.booking.cancelled";
876
969
  /** The event is in the outbox; every active endpoint on the sandbox receives it within seconds */
877
970
  queued: boolean;
878
971
  };
879
972
  }
880
973
  export interface SandboxBookingsList {
881
- /** Simulated OTA bookings on the sandbox, newest first */
974
+ /** Simulated bookings on the sandbox (OTA and website), newest first */
882
975
  bookings: Array<{
883
976
  /** The PMS booking id, the one the webhook carries */
884
977
  bookingId: number;
@@ -887,6 +980,7 @@ export interface SandboxBookingsList {
887
980
  /** The pretend channel-side id */
888
981
  channelBookingId: string;
889
982
  otaName: string;
983
+ /** The stay's state. GET /channel-bookings reads the same booking as status CONFIRMED (or CANCELLED) with stayStatus UPCOMING */
890
984
  status: "UPCOMING" | "CANCELLED";
891
985
  guestName: string;
892
986
  checkIn: string;
@@ -894,9 +988,9 @@ export interface SandboxBookingsList {
894
988
  nights: number;
895
989
  rooms: number;
896
990
  roomTypeId: number;
897
- /** Major units, per room per night */
991
+ /** Major units, per room per night: the average when the nights differ. Each night is priced from the sandbox's own record, what GET /rates gives for the room type's first rate plan */
898
992
  nightlyRate: number;
899
- /** Major units */
993
+ /** Major units: every night's price × rooms */
900
994
  total: number;
901
995
  currency: string;
902
996
  paidByOta: boolean;
@@ -905,7 +999,7 @@ export interface SandboxBookingsList {
905
999
  createdAt: string;
906
1000
  /** What this call put on the wire for the sandbox's webhook endpoints */
907
1001
  webhook: {
908
- eventType: "channel.booking.created" | "channel.booking.modified" | "channel.booking.cancelled";
1002
+ eventType: "channel.booking.created" | "channel.booking.modified" | "channel.booking.cancelled" | "direct.booking.created" | "direct.booking.cancelled";
909
1003
  /** The event is in the outbox; every active endpoint on the sandbox receives it within seconds */
910
1004
  queued: boolean;
911
1005
  };
@@ -1103,6 +1197,36 @@ export interface Operations {
1103
1197
  body: undefined;
1104
1198
  response: ChannelBooking;
1105
1199
  };
1200
+ /** The bookings guests made on the hotel's own website, in the webhook's shape */
1201
+ "GET /direct-bookings": {
1202
+ path: undefined;
1203
+ query: {
1204
+ since?: string;
1205
+ status?: "CONFIRMED" | "CANCELLED";
1206
+ limit?: number;
1207
+ cursor?: string;
1208
+ };
1209
+ body: undefined;
1210
+ response: ChannelBookingsList;
1211
+ };
1212
+ /** One website booking, the webhook's shape */
1213
+ "GET /direct-bookings/{bookingId}": {
1214
+ path: {
1215
+ bookingId: string | number;
1216
+ };
1217
+ query: undefined;
1218
+ body: undefined;
1219
+ response: ChannelBooking;
1220
+ };
1221
+ /** Cancel a website booking and refund it: per its policy, in full, or not at all */
1222
+ "POST /direct-bookings/{bookingId}/cancel": {
1223
+ path: {
1224
+ bookingId: string | number;
1225
+ };
1226
+ query: undefined;
1227
+ body: DirectBookingCancel;
1228
+ response: DirectBookingCancelResult;
1229
+ };
1106
1230
  /** Simulated OTA bookings on the sandbox, newest first */
1107
1231
  "GET /sandbox/bookings": {
1108
1232
  path: undefined;
@@ -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.2.0";
7
+ exports.SDK_VERSION = "0.4.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";
@@ -26,6 +26,8 @@ exports.LIMITS = {
26
26
  "bookingsPerMinute": 20,
27
27
  "propertyBookingsPerMinute": 40,
28
28
  "propertyBookingsPerDay": 500,
29
+ "directCancelsPerMinute": 10,
30
+ "propertyDirectCancelsPerDay": 50,
29
31
  "companyRequestsPerMinute": 1200,
30
32
  "maxNightsPerBooking": 90
31
33
  };
@@ -96,6 +98,8 @@ exports.SCOPES = [
96
98
  "catalog:write",
97
99
  "channel-modifiers:write",
98
100
  "channel-bookings:read",
101
+ "direct-bookings:read",
102
+ "direct-bookings:cancel",
99
103
  "bookings:read",
100
104
  "bookings:write",
101
105
  "bookings:payments"
@@ -127,6 +131,9 @@ exports.OPERATIONS = {
127
131
  "POST /rates/resend": { idempotent: true, bodyRequired: false },
128
132
  "GET /channel-bookings": { idempotent: false, bodyRequired: false },
129
133
  "GET /channel-bookings/{bookingId}": { idempotent: false, bodyRequired: false },
134
+ "GET /direct-bookings": { idempotent: false, bodyRequired: false },
135
+ "GET /direct-bookings/{bookingId}": { idempotent: false, bodyRequired: false },
136
+ "POST /direct-bookings/{bookingId}/cancel": { idempotent: true, bodyRequired: false },
130
137
  "GET /sandbox/bookings": { idempotent: false, bodyRequired: false },
131
138
  "POST /sandbox/bookings": { idempotent: true, bodyRequired: true },
132
139
  "POST /sandbox/bookings/{bookingId}/cancel": { idempotent: false, bodyRequired: false },
@@ -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");
@@ -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
- /** channel.booking.created · channel.booking.modified · channel.booking.cancelled · channel.sync.* · zimmerstack.ping */
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";