@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.
@@ -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";
@@ -1,3 +1,29 @@
1
+ /**
2
+ * Verifying a webhook ZimmerStack sent you (Standard Webhooks: the `webhook-id`, `webhook-timestamp` and
3
+ * `webhook-signature` headers). Uses Web Crypto, so it runs on Node and on edge runtimes alike.
4
+ */
5
+ /** An OTA booking arrived, changed or was cancelled (through the channel manager). */
6
+ export const OTA_BOOKING_EVENT_TYPES = ["channel.booking.created", "channel.booking.modified", "channel.booking.cancelled"];
7
+ /**
8
+ * A guest booked, or cancelled, on the hotel's own website through ZimmerStack's booking engine. The same
9
+ * booking object as the OTA events, in a family of its own: an endpoint receives these only when it lists
10
+ * the two types. There is no modified event.
11
+ */
12
+ export const WEBSITE_BOOKING_EVENT_TYPES = ["direct.booking.created", "direct.booking.cancelled"];
13
+ /** Every event whose `data.booking` is a booking, of either family. */
14
+ export const BOOKING_EVENT_TYPES = [...OTA_BOOKING_EVENT_TYPES, ...WEBSITE_BOOKING_EVENT_TYPES];
15
+ const isType = (list, event) => typeof event?.type === "string" && list.includes(event.type);
16
+ /**
17
+ * True for `direct.booking.created` and `direct.booking.cancelled`: a booking made on the hotel's own
18
+ * website. A PMS that pushes room counts must put it in its own calendar before its next push.
19
+ */
20
+ export function isWebsiteBookingEvent(event) {
21
+ return isType(WEBSITE_BOOKING_EVENT_TYPES, event) && Boolean(event.data?.booking);
22
+ }
23
+ /** True for `channel.booking.created`, `.modified` and `.cancelled`: a booking an OTA sent. */
24
+ export function isOtaBookingEvent(event) {
25
+ return isType(OTA_BOOKING_EVENT_TYPES, event) && Boolean(event.data?.booking);
26
+ }
1
27
  export class ZimmerStackWebhookError extends Error {
2
28
  /** Why the delivery was refused. Answer 400 and do not act on the body. */
3
29
  reason;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zimmerstack/connect",
3
- "version": "0.2.0",
3
+ "version": "0.4.0",
4
4
  "description": "Official Node.js client for the ZimmerStack Connect API: rates, availability, stay rules, prices per channel and bookings, with pacing, safe retries and idempotency built in. Ships an MCP server for coding agents.",
5
5
  "license": "MIT",
6
6
  "homepage": "https://docs.zimmerstack.com/sdk",