@zimmerstack/connect 0.7.0 → 0.9.1

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.
Files changed (51) hide show
  1. package/AGENTS.md +305 -25
  2. package/README.md +572 -56
  3. package/dist/cjs/client.d.ts +528 -13
  4. package/dist/cjs/client.js +778 -46
  5. package/dist/cjs/doctor.d.ts +86 -0
  6. package/dist/cjs/doctor.js +689 -0
  7. package/dist/cjs/errors.d.ts +6 -2
  8. package/dist/cjs/errors.js +7 -2
  9. package/dist/cjs/generated.d.ts +2873 -203
  10. package/dist/cjs/generated.js +222 -8
  11. package/dist/cjs/grid.d.ts +6 -1
  12. package/dist/cjs/grid.js +8 -0
  13. package/dist/cjs/index.d.ts +14 -5
  14. package/dist/cjs/index.js +41 -1
  15. package/dist/cjs/key.d.ts +39 -0
  16. package/dist/cjs/key.js +85 -0
  17. package/dist/cjs/money.d.ts +81 -0
  18. package/dist/cjs/money.js +172 -0
  19. package/dist/cjs/notices.d.ts +44 -0
  20. package/dist/cjs/notices.js +64 -0
  21. package/dist/cjs/shownOnce.d.ts +42 -0
  22. package/dist/cjs/shownOnce.js +83 -0
  23. package/dist/cjs/webhooks.d.ts +182 -3
  24. package/dist/cjs/webhooks.js +75 -1
  25. package/dist/esm/client.d.ts +528 -13
  26. package/dist/esm/client.js +776 -46
  27. package/dist/esm/doctor.d.ts +86 -0
  28. package/dist/esm/doctor.js +685 -0
  29. package/dist/esm/errors.d.ts +6 -2
  30. package/dist/esm/errors.js +7 -2
  31. package/dist/esm/generated.d.ts +2873 -203
  32. package/dist/esm/generated.js +221 -7
  33. package/dist/esm/grid.d.ts +6 -1
  34. package/dist/esm/grid.js +7 -0
  35. package/dist/esm/index.d.ts +14 -5
  36. package/dist/esm/index.js +8 -3
  37. package/dist/esm/key.d.ts +39 -0
  38. package/dist/esm/key.js +81 -0
  39. package/dist/esm/mcp/cli.js +95 -11
  40. package/dist/esm/mcp/reference.generated.js +5741 -1008
  41. package/dist/esm/mcp/server.d.ts +14 -6
  42. package/dist/esm/mcp/server.js +451 -25
  43. package/dist/esm/money.d.ts +81 -0
  44. package/dist/esm/money.js +161 -0
  45. package/dist/esm/notices.d.ts +44 -0
  46. package/dist/esm/notices.js +56 -0
  47. package/dist/esm/shownOnce.d.ts +42 -0
  48. package/dist/esm/shownOnce.js +77 -0
  49. package/dist/esm/webhooks.d.ts +182 -3
  50. package/dist/esm/webhooks.js +69 -0
  51. package/package.json +2 -2
@@ -1,4 +1,4 @@
1
- import type { ChannelBooking } from "./generated.js";
1
+ import type { ChannelBooking, ChannelConnectEvent, ChannelDriftEvent, ChannelSyncEvent, Status, SupportTicket } from "./generated.js";
2
2
  /**
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.
@@ -22,8 +22,44 @@ export declare const BOOKING_EVENT_TYPES: readonly ["channel.booking.created", "
22
22
  export type OtaBookingEventType = (typeof OTA_BOOKING_EVENT_TYPES)[number];
23
23
  export type WebsiteBookingEventType = (typeof WEBSITE_BOOKING_EVENT_TYPES)[number];
24
24
  export type BookingEventType = (typeof BOOKING_EVENT_TYPES)[number];
25
+ /**
26
+ * A channel problem and its end: a refused value, a disconnect, room counts or prices that stopped going
27
+ * out, a setting changed (`data.sync.event` says which), then `recovered` when it is over.
28
+ */
29
+ export declare const SYNC_EVENT_TYPES: readonly ["channel.sync.alert", "channel.sync.recovered"];
30
+ /**
31
+ * The nightly read of the channel manager found it holding something other than what you sent
32
+ * (`detected`: the nights, and which were sent again), then found them agreeing again (`healed`).
33
+ * A family of its own: an endpoint receives it only when it lists the type.
34
+ */
35
+ export declare const DRIFT_EVENT_TYPES: readonly ["channel.drift.detected", "channel.drift.healed"];
36
+ /**
37
+ * How a one-time connect link ended (`zs.connectLinks.create`): the hotel's person pressed Start selling
38
+ * on the hosted page (`completed`), or the link ran out first (`expired`). A family of its own: an
39
+ * endpoint receives it only when it lists the type. It names its hotel, so it is in the hotel's event
40
+ * log with a sequence.
41
+ */
42
+ export declare const CONNECT_EVENT_TYPES: readonly ["channel.connect.completed", "channel.connect.expired"];
43
+ /**
44
+ * ZimmerStack's staff recorded an incident that touches one of your hotels, said where it stands, or
45
+ * ended it. Sent ONCE PER ENDPOINT, not once per hotel: `data.incident.properties` names your hotels it
46
+ * touches. It carries no top-level `property` and no `sequence`, is not in the event log, and Recover
47
+ * since does not replay it: `zs.status.get()` is the read. Only for an endpoint that lists the types.
48
+ */
49
+ export declare const INCIDENT_EVENT_TYPES: readonly ["platform.incident.opened", "platform.incident.updated", "platform.incident.resolved"];
50
+ /**
51
+ * ZimmerStack answered one of your support tickets (`replied`, with the message) or closed it. Sent to
52
+ * your COMPANY endpoints of the ticket's mode that list the type. No top-level `property`, no `sequence`,
53
+ * not in the event log: `zs.supportTickets.get(id)` is the read.
54
+ */
55
+ export declare const SUPPORT_TICKET_EVENT_TYPES: readonly ["support.ticket.replied", "support.ticket.closed"];
56
+ export type SyncEventType = (typeof SYNC_EVENT_TYPES)[number];
57
+ export type DriftEventType = (typeof DRIFT_EVENT_TYPES)[number];
58
+ export type ConnectEventType = (typeof CONNECT_EVENT_TYPES)[number];
59
+ export type IncidentEventType = (typeof INCIDENT_EVENT_TYPES)[number];
60
+ export type SupportTicketEventType = (typeof SUPPORT_TICKET_EVENT_TYPES)[number];
25
61
  /** Every type an endpoint can receive. A newer API may add more: `WebhookEvent.type` stays a string. */
26
- export type WebhookEventType = BookingEventType | "channel.sync.alert" | "channel.sync.recovered" | "zimmerstack.ping";
62
+ export type WebhookEventType = BookingEventType | SyncEventType | DriftEventType | ConnectEventType | IncidentEventType | SupportTicketEventType | "zimmerstack.ping";
27
63
  /** What every delivery carries. Deliveries are at-least-once: dedupe on `id`, order on `occurredAt`. */
28
64
  export interface WebhookEvent {
29
65
  /** "evt_<uuid>", the same on every retry and on every endpoint. */
@@ -31,13 +67,26 @@ export interface WebhookEvent {
31
67
  /**
32
68
  * channel.booking.created · channel.booking.modified · channel.booking.cancelled (an OTA booking) ·
33
69
  * direct.booking.created · direct.booking.modified · direct.booking.cancelled (a booking on the hotel's own website) ·
34
- * channel.sync.* · zimmerstack.ping. Narrow it with `isOtaBookingEvent` and `isWebsiteBookingEvent`.
70
+ * channel.sync.* · channel.drift.* · channel.connect.* · platform.incident.* · support.ticket.* · zimmerstack.ping.
71
+ * Narrow it with `isOtaBookingEvent`, `isWebsiteBookingEvent`, `isSyncEvent`, `isDriftEvent`, `isConnectEvent`,
72
+ * `isIncidentEvent` and `isSupportTicketEvent`.
35
73
  */
36
74
  type: string;
37
75
  apiVersion: string;
38
76
  occurredAt: string;
39
77
  /** "test" for events from a sandbox or the "send test" button. */
40
78
  mode: "live" | "test";
79
+ /**
80
+ * The event's place in its hotel's ordered log: one higher than the hotel's last event, across every
81
+ * type. When it is not the one after the last you applied, read what you missed with
82
+ * `zs.events.all({ after })`. Absent on a Test button's sample and on events from before 22 Nov 2026.
83
+ */
84
+ sequence?: number;
85
+ /**
86
+ * The hotel the event is about. NOT THERE on `platform.incident.*` and `support.ticket.*`: those are about
87
+ * your account, not one hotel. If your endpoint lists them, check `isIncidentEvent` and
88
+ * `isSupportTicketEvent` before you read it.
89
+ */
41
90
  property: {
42
91
  id: number;
43
92
  name: string;
@@ -82,6 +131,136 @@ export type OtaBookingEvent = BookingEvent & {
82
131
  export declare function isWebsiteBookingEvent(event: WebhookEvent): event is WebsiteBookingEvent;
83
132
  /** True for `channel.booking.created`, `.modified` and `.cancelled`: a booking an OTA sent. */
84
133
  export declare function isOtaBookingEvent(event: WebhookEvent): event is OtaBookingEvent;
134
+ /** A channel problem or its end, with `data.sync`. */
135
+ export type SyncEvent = WebhookEvent & {
136
+ type: SyncEventType;
137
+ data: {
138
+ sync: ChannelSyncEvent["data"]["sync"];
139
+ [key: string]: unknown;
140
+ };
141
+ };
142
+ /** What a nightly read found changed on the channel manager's side, with `data.drift`. */
143
+ export type DriftEvent = WebhookEvent & {
144
+ type: DriftEventType;
145
+ data: {
146
+ drift: ChannelDriftEvent["data"]["drift"];
147
+ [key: string]: unknown;
148
+ };
149
+ };
150
+ /** True for `channel.sync.alert` and `channel.sync.recovered`: `event.data.sync` says which problem, on which channel. */
151
+ export declare function isSyncEvent(event: WebhookEvent): event is SyncEvent;
152
+ /** True for `channel.drift.detected` and `channel.drift.healed`: `event.data.drift.cells` names the nights. */
153
+ export declare function isDriftEvent(event: WebhookEvent): event is DriftEvent;
154
+ /** How a one-time connect link ended, with `data.connect`. It names its hotel (`property`) and has a `sequence`. */
155
+ export type ConnectEvent = WebhookEvent & {
156
+ type: ConnectEventType;
157
+ data: {
158
+ connect: ChannelConnectEvent["data"]["connect"];
159
+ [key: string]: unknown;
160
+ };
161
+ };
162
+ /**
163
+ * True for `channel.connect.completed` and `channel.connect.expired`. Match it to your link by
164
+ * `data.connect.linkId` (the id `zs.connectLinks.create` answered; the event never carries the link's
165
+ * address or your `reference`, because the hotel's own endpoints hear it too).
166
+ *
167
+ * `completed`: `selling` is true, `channelId` is the connection (`zs.channels.list()`), and
168
+ * `futureBookings` says what became of the booking site's upcoming bookings: "pulled" (they arrive as
169
+ * `channel.booking.created`), "failed" (the pull did not run; selling is on all the same) or "none"
170
+ * (that booking site offers no such pull). `expired`: `opened` says whether anyone opened the link, and
171
+ * `channelId` is set when the page saved a connection nobody started: it exists, paused.
172
+ */
173
+ export declare function isConnectEvent(event: WebhookEvent): event is ConnectEvent;
174
+ /** An incident, as its events carry it: where it stands now, what we said with this change, and which of YOUR hotels it touches. */
175
+ export interface IncidentInEvent {
176
+ /** The same on opened, every updated and resolved, and on `zs.status.get()`: group on it. */
177
+ id: number;
178
+ /** api · bookings_in · ari_out · ota:<booking site>. */
179
+ component: string;
180
+ componentName: string;
181
+ severity: Status["incidents"]["open"][number]["severity"];
182
+ status: Status["incidents"]["open"][number]["status"];
183
+ title: string;
184
+ /** What ZimmerStack said with this change, in plain words. */
185
+ message: string;
186
+ startedAt: string;
187
+ updatedAt: string;
188
+ resolvedAt: string | null;
189
+ /** Your hotels it touches: `all` when it touches every hotel, else their ids (at most 200; `count` has the real number). */
190
+ properties: {
191
+ all: boolean;
192
+ count: number;
193
+ ids: number[];
194
+ truncated: boolean;
195
+ };
196
+ }
197
+ /**
198
+ * A `platform.incident.*` delivery. It is about your account, so it has NO `property` and NO `sequence`:
199
+ * it is not in any hotel's event log. `zs.status.get()` reads the same incident at any time.
200
+ */
201
+ export interface IncidentEvent {
202
+ /** "evt_<uuid>", the same on every retry. */
203
+ id: string;
204
+ type: IncidentEventType;
205
+ apiVersion: string;
206
+ occurredAt: string;
207
+ mode: "live" | "test";
208
+ data: {
209
+ incident: IncidentInEvent;
210
+ };
211
+ }
212
+ /** A support ticket, as its events carry it: where it stands, never the whole thread. */
213
+ export interface TicketInEvent {
214
+ id: number;
215
+ subject: string;
216
+ severity: SupportTicket["severity"];
217
+ status: SupportTicket["status"];
218
+ properties: {
219
+ all: boolean;
220
+ ids: number[];
221
+ };
222
+ openedAt: string;
223
+ lastMessageAt: string;
224
+ closedAt: string | null;
225
+ }
226
+ /**
227
+ * A `support.ticket.*` delivery. `data.message` is ZimmerStack's reply on `replied`, and the closing
228
+ * note on `closed` when there was one (null otherwise). A long message is cut (`truncated`):
229
+ * `zs.supportTickets.get(id)` has it whole. NO `property` and NO `sequence`.
230
+ */
231
+ export interface SupportTicketEvent {
232
+ id: string;
233
+ type: SupportTicketEventType;
234
+ apiVersion: string;
235
+ occurredAt: string;
236
+ mode: "live" | "test";
237
+ data: {
238
+ ticket: TicketInEvent;
239
+ message: {
240
+ id: number;
241
+ author: "zimmerstack";
242
+ body: string;
243
+ truncated: boolean;
244
+ createdAt: string;
245
+ } | null;
246
+ };
247
+ }
248
+ /** Anything a guard can look at: a verified delivery, or a body you parsed yourself. */
249
+ type Typed = {
250
+ type?: unknown;
251
+ data?: unknown;
252
+ } | null | undefined;
253
+ /**
254
+ * True for `platform.incident.opened`, `.updated` and `.resolved`. Check it BEFORE reading
255
+ * `event.property`: an incident event has none.
256
+ *
257
+ * @example
258
+ * const event = await verifyWebhook(rawBody, headers, secret);
259
+ * if (isIncidentEvent(event)) return showBanner(event.data.incident.title, event.data.incident.status, event.data.incident.properties.ids);
260
+ */
261
+ export declare function isIncidentEvent(event: Typed): event is IncidentEvent;
262
+ /** True for `support.ticket.replied` and `support.ticket.closed`. Check it BEFORE reading `event.property`: it has none. */
263
+ export declare function isSupportTicketEvent(event: Typed): event is SupportTicketEvent;
85
264
  export declare class ZimmerStackWebhookError extends Error {
86
265
  /** Why the delivery was refused. Answer 400 and do not act on the body. */
87
266
  readonly reason: "missing_headers" | "stale_timestamp" | "bad_signature" | "bad_body";
@@ -1,8 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ZimmerStackWebhookError = exports.BOOKING_EVENT_TYPES = exports.WEBSITE_BOOKING_EVENT_TYPES = exports.OTA_BOOKING_EVENT_TYPES = void 0;
3
+ exports.ZimmerStackWebhookError = exports.SUPPORT_TICKET_EVENT_TYPES = exports.INCIDENT_EVENT_TYPES = exports.CONNECT_EVENT_TYPES = exports.DRIFT_EVENT_TYPES = exports.SYNC_EVENT_TYPES = exports.BOOKING_EVENT_TYPES = exports.WEBSITE_BOOKING_EVENT_TYPES = exports.OTA_BOOKING_EVENT_TYPES = void 0;
4
4
  exports.isWebsiteBookingEvent = isWebsiteBookingEvent;
5
5
  exports.isOtaBookingEvent = isOtaBookingEvent;
6
+ exports.isSyncEvent = isSyncEvent;
7
+ exports.isDriftEvent = isDriftEvent;
8
+ exports.isConnectEvent = isConnectEvent;
9
+ exports.isIncidentEvent = isIncidentEvent;
10
+ exports.isSupportTicketEvent = isSupportTicketEvent;
6
11
  exports.verifyWebhook = verifyWebhook;
7
12
  /**
8
13
  * Verifying a webhook ZimmerStack sent you (Standard Webhooks: the `webhook-id`, `webhook-timestamp` and
@@ -24,6 +29,37 @@ exports.OTA_BOOKING_EVENT_TYPES = ["channel.booking.created", "channel.booking.m
24
29
  exports.WEBSITE_BOOKING_EVENT_TYPES = ["direct.booking.created", "direct.booking.modified", "direct.booking.cancelled"];
25
30
  /** Every event whose `data.booking` is a booking, of either family. */
26
31
  exports.BOOKING_EVENT_TYPES = [...exports.OTA_BOOKING_EVENT_TYPES, ...exports.WEBSITE_BOOKING_EVENT_TYPES];
32
+ /**
33
+ * A channel problem and its end: a refused value, a disconnect, room counts or prices that stopped going
34
+ * out, a setting changed (`data.sync.event` says which), then `recovered` when it is over.
35
+ */
36
+ exports.SYNC_EVENT_TYPES = ["channel.sync.alert", "channel.sync.recovered"];
37
+ /**
38
+ * The nightly read of the channel manager found it holding something other than what you sent
39
+ * (`detected`: the nights, and which were sent again), then found them agreeing again (`healed`).
40
+ * A family of its own: an endpoint receives it only when it lists the type.
41
+ */
42
+ exports.DRIFT_EVENT_TYPES = ["channel.drift.detected", "channel.drift.healed"];
43
+ /**
44
+ * How a one-time connect link ended (`zs.connectLinks.create`): the hotel's person pressed Start selling
45
+ * on the hosted page (`completed`), or the link ran out first (`expired`). A family of its own: an
46
+ * endpoint receives it only when it lists the type. It names its hotel, so it is in the hotel's event
47
+ * log with a sequence.
48
+ */
49
+ exports.CONNECT_EVENT_TYPES = ["channel.connect.completed", "channel.connect.expired"];
50
+ /**
51
+ * ZimmerStack's staff recorded an incident that touches one of your hotels, said where it stands, or
52
+ * ended it. Sent ONCE PER ENDPOINT, not once per hotel: `data.incident.properties` names your hotels it
53
+ * touches. It carries no top-level `property` and no `sequence`, is not in the event log, and Recover
54
+ * since does not replay it: `zs.status.get()` is the read. Only for an endpoint that lists the types.
55
+ */
56
+ exports.INCIDENT_EVENT_TYPES = ["platform.incident.opened", "platform.incident.updated", "platform.incident.resolved"];
57
+ /**
58
+ * ZimmerStack answered one of your support tickets (`replied`, with the message) or closed it. Sent to
59
+ * your COMPANY endpoints of the ticket's mode that list the type. No top-level `property`, no `sequence`,
60
+ * not in the event log: `zs.supportTickets.get(id)` is the read.
61
+ */
62
+ exports.SUPPORT_TICKET_EVENT_TYPES = ["support.ticket.replied", "support.ticket.closed"];
27
63
  const isType = (list, event) => typeof event?.type === "string" && list.includes(event.type);
28
64
  /**
29
65
  * True for `direct.booking.created`, `direct.booking.modified` and `direct.booking.cancelled`: a booking
@@ -37,6 +73,44 @@ function isWebsiteBookingEvent(event) {
37
73
  function isOtaBookingEvent(event) {
38
74
  return isType(exports.OTA_BOOKING_EVENT_TYPES, event) && Boolean(event.data?.booking);
39
75
  }
76
+ /** True for `channel.sync.alert` and `channel.sync.recovered`: `event.data.sync` says which problem, on which channel. */
77
+ function isSyncEvent(event) {
78
+ return isType(exports.SYNC_EVENT_TYPES, event) && Boolean(event.data?.sync);
79
+ }
80
+ /** True for `channel.drift.detected` and `channel.drift.healed`: `event.data.drift.cells` names the nights. */
81
+ function isDriftEvent(event) {
82
+ return isType(exports.DRIFT_EVENT_TYPES, event) && Boolean(event.data?.drift);
83
+ }
84
+ /**
85
+ * True for `channel.connect.completed` and `channel.connect.expired`. Match it to your link by
86
+ * `data.connect.linkId` (the id `zs.connectLinks.create` answered; the event never carries the link's
87
+ * address or your `reference`, because the hotel's own endpoints hear it too).
88
+ *
89
+ * `completed`: `selling` is true, `channelId` is the connection (`zs.channels.list()`), and
90
+ * `futureBookings` says what became of the booking site's upcoming bookings: "pulled" (they arrive as
91
+ * `channel.booking.created`), "failed" (the pull did not run; selling is on all the same) or "none"
92
+ * (that booking site offers no such pull). `expired`: `opened` says whether anyone opened the link, and
93
+ * `channelId` is set when the page saved a connection nobody started: it exists, paused.
94
+ */
95
+ function isConnectEvent(event) {
96
+ return isType(exports.CONNECT_EVENT_TYPES, event) && Boolean(event.data?.connect);
97
+ }
98
+ const dataOf = (event) => (event && typeof event.data === "object" && event.data !== null ? event.data : {});
99
+ /**
100
+ * True for `platform.incident.opened`, `.updated` and `.resolved`. Check it BEFORE reading
101
+ * `event.property`: an incident event has none.
102
+ *
103
+ * @example
104
+ * const event = await verifyWebhook(rawBody, headers, secret);
105
+ * if (isIncidentEvent(event)) return showBanner(event.data.incident.title, event.data.incident.status, event.data.incident.properties.ids);
106
+ */
107
+ function isIncidentEvent(event) {
108
+ return isType(exports.INCIDENT_EVENT_TYPES, event) && Boolean(dataOf(event).incident);
109
+ }
110
+ /** True for `support.ticket.replied` and `support.ticket.closed`. Check it BEFORE reading `event.property`: it has none. */
111
+ function isSupportTicketEvent(event) {
112
+ return isType(exports.SUPPORT_TICKET_EVENT_TYPES, event) && Boolean(dataOf(event).ticket);
113
+ }
40
114
  class ZimmerStackWebhookError extends Error {
41
115
  /** Why the delivery was refused. Answer 400 and do not act on the body. */
42
116
  reason;