@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,7 +1,7 @@
1
1
  // GENERATED by scripts/generate.mjs from the Connect API's public contract (ZimmerStack Connect API v1).
2
2
  // Do not edit: change the contract, then run `pnpm --dir apps/connect-sdk run generate`.
3
3
  /** This package's version, sent as the user agent so ZimmerStack can tell which client a request came from. */
4
- export const SDK_VERSION = "0.7.0";
4
+ export const SDK_VERSION = "0.9.1";
5
5
  /** Where the API lives. The key is sent nowhere else. */
6
6
  export const API_ORIGIN = "https://api.zimmerstack.com";
7
7
  export const API_PREFIX = "/api/v1/connect-api/v1";
@@ -16,10 +16,14 @@ export const LIMITS = {
16
16
  "propertyWritesPerMinute": 60,
17
17
  "propertyCellsPerMinute": 20000,
18
18
  "ipRequestsPerMinute": 240,
19
+ "ipAuthFailuresPerMinute": 20,
20
+ "keyAuthFailuresPerMinute": 5,
21
+ "globalUnauthenticatedPerMinute": 1200,
22
+ "globalRequestsPerMinute": 3000,
19
23
  "maxUpdatesPerRequest": 1000,
20
24
  "maxCellsPerRequest": 5000,
21
25
  "maxBodyBytes": 1048576,
22
- "horizonDays": 365,
26
+ "horizonDays": 500,
23
27
  "bookingsPerMinute": 20,
24
28
  "propertyBookingsPerMinute": 40,
25
29
  "propertyBookingsPerDay": 500,
@@ -71,6 +75,14 @@ export const ERROR_CODES = [
71
75
  "CATALOG_CONFLICT",
72
76
  "CATALOG_BUSY",
73
77
  "CHANNEL_MANAGER_ERROR",
78
+ "WEBHOOK_ENDPOINT_NOT_FOUND",
79
+ "WEBHOOK_DELIVERY_NOT_FOUND",
80
+ "WEBHOOK_ENDPOINT_LIMIT",
81
+ "WEBHOOK_ENDPOINT_NOT_ACTIVE",
82
+ "WEBHOOK_ENDPOINT_SUSPENDED",
83
+ "WEBHOOK_PAYLOAD_EXPIRED",
84
+ "WEBHOOK_ACCESS_ENDED",
85
+ "WEBHOOKS_UNAVAILABLE",
74
86
  "PROPERTY_REQUIRED",
75
87
  "PROPERTY_NOT_FOUND",
76
88
  "ARI_NOT_AUTHORITATIVE",
@@ -95,8 +107,23 @@ export const ERROR_CODES = [
95
107
  "SANDBOX_LIMIT",
96
108
  "CONFIRMATION_MISMATCH",
97
109
  "PROPERTY_NOT_REMOVABLE",
110
+ "PROPERTY_NOT_CHANGEABLE",
98
111
  "PROPERTY_BUSY",
99
- "PRICE_UNAVAILABLE"
112
+ "PRICE_UNAVAILABLE",
113
+ "CONNECT_LINK_NOT_FOUND",
114
+ "CONNECT_LINKS_UNAVAILABLE",
115
+ "CHANNEL_NOT_AVAILABLE",
116
+ "LIVE_KEY_REQUIRED",
117
+ "NOT_READY",
118
+ "KEY_NOT_FOUND",
119
+ "KEY_LIMIT",
120
+ "KEY_REVOKED",
121
+ "KEY_ALREADY_ROTATING",
122
+ "SCOPES_INVALID",
123
+ "ALLOWED_CIDRS_INVALID",
124
+ "REASON_REQUIRED",
125
+ "SUPPORT_TICKET_NOT_FOUND",
126
+ "SUPPORT_TICKET_CLOSED"
100
127
  ];
101
128
  /** What a key may do. The hotel's owner (or, for a vendor's key, the vendor) chose them when the key was made. */
102
129
  export const SCOPES = [
@@ -110,16 +137,161 @@ export const SCOPES = [
110
137
  "bookings:read",
111
138
  "bookings:write",
112
139
  "bookings:payments",
113
- "properties:write"
140
+ "properties:write",
141
+ "webhooks:manage",
142
+ "channels:connect",
143
+ "keys:manage",
144
+ "billing:read",
145
+ "support:write"
114
146
  ];
115
147
  /** When a channel's price modifier takes effect. Show it where a person saves one. */
116
148
  export const MODIFIER_TAKES_EFFECT = "Saving a modifier makes the channel manager send that channel every date again, so prices already on the channel move to the new rule within minutes.";
149
+ /** Every notice an ARI write's answer may carry (`notices`): its stable code, its level, which writes it rides on and what it means. Branch on the code; show the notice's own message and action. */
150
+ export const NOTICES = [
151
+ {
152
+ "code": "NOT_SOURCE_OF_TRUTH",
153
+ "level": "warning",
154
+ "on": "every write",
155
+ "means": "The hotel is not live for this software yet: prices and stay rules sent now are stored and wait for go-live, and of room counts only one that lowers what is on sale goes out."
156
+ },
157
+ {
158
+ "code": "ROOM_TYPE_NOT_LINKED",
159
+ "level": "warning",
160
+ "on": "availability",
161
+ "means": "The room type has no link to the channel manager: its count is kept and sent nowhere."
162
+ },
163
+ {
164
+ "code": "PLAN_NOT_LINKED",
165
+ "level": "warning",
166
+ "on": "rates, restrictions",
167
+ "means": "The rate plan has no link to the channel manager: its values are kept and sent nowhere."
168
+ },
169
+ {
170
+ "code": "PLAN_NOT_MAPPED",
171
+ "level": "warning",
172
+ "on": "rates, restrictions",
173
+ "means": "The rate plan is on the channel manager and no connected channel that is switched on sells it: nothing sells or stops because of this write."
174
+ },
175
+ {
176
+ "code": "ROOM_STILL_ON_SALE",
177
+ "level": "warning",
178
+ "on": "restrictions",
179
+ "means": "You stop-sold one rate plan; the room is still on sale through its other plans (otherRatePlanIds)."
180
+ },
181
+ {
182
+ "code": "OTA_LINKED_RATES_NOT_REACHED",
183
+ "level": "info",
184
+ "on": "restrictions",
185
+ "means": "A stop-sell does not reach a rate an OTA links on its own side: only the room's count closes it."
186
+ },
187
+ {
188
+ "code": "STAY_RULES_FROM_ANOTHER_PLAN",
189
+ "level": "warning",
190
+ "on": "restrictions",
191
+ "means": "On a channel, the OTA rate this plan sells takes its stay rules from another plan's row (otherRatePlanIds): a stay rule here alone does not reach it."
192
+ },
193
+ {
194
+ "code": "PER_OTA_PLANS_FOLLOW",
195
+ "level": "info",
196
+ "on": "rates, restrictions",
197
+ "means": "The plan has per-OTA plans: its price is copied onto them and they follow its stay rules."
198
+ },
199
+ {
200
+ "code": "PER_OTA_PLAN_FOLLOWS_PARENT",
201
+ "level": "warning",
202
+ "on": "rates, restrictions",
203
+ "means": "The plan you wrote is a per-OTA plan: its parent's price and stay rules replace what is set here."
204
+ },
205
+ {
206
+ "code": "VALUE_HELD",
207
+ "level": "warning",
208
+ "on": "rates, restrictions",
209
+ "means": "The value equals one the channel manager refused: it is held with its words, not sent again."
210
+ },
211
+ {
212
+ "code": "COUNT_WAS_REFUSED",
213
+ "level": "warning",
214
+ "on": "availability",
215
+ "means": "The last count sent for these nights was refused by the channel manager and nothing has landed since."
216
+ },
217
+ {
218
+ "code": "COUNT_ZERO_IS_NOT_STOP_SELL",
219
+ "level": "info",
220
+ "on": "availability",
221
+ "means": "You sent availability 0: a count that closes every plan and channel, and that the next OTA cancellation or your next count moves. Not a switch."
222
+ },
223
+ {
224
+ "code": "STOP_SELL_IS_NOT_A_COUNT",
225
+ "level": "info",
226
+ "on": "restrictions",
227
+ "means": "You sent a stop-sell: a switch on those plans. The room's count is untouched."
228
+ },
229
+ {
230
+ "code": "COUNT_OPEN_BUT_PLANS_STOPPED",
231
+ "level": "warning",
232
+ "on": "availability",
233
+ "means": "You sent a count above 0 for nights on which every plan of the room is stop-sold: the room does not sell."
234
+ },
235
+ {
236
+ "code": "NEW_DATES_OPEN_CLOSED",
237
+ "level": "warning",
238
+ "on": "availability",
239
+ "means": "The hotel's rule \"new dates open closed\" will set these nights to 0 when they come on sale."
240
+ },
241
+ {
242
+ "code": "FAR_NIGHTS_NEED_A_COUNT",
243
+ "level": "warning",
244
+ "on": "rates, restrictions",
245
+ "means": "A night past day 365 with no count of its own goes out closed, whatever its price or stay rules."
246
+ },
247
+ {
248
+ "code": "ENGINE_WILL_REPRICE",
249
+ "level": "warning",
250
+ "on": "rates",
251
+ "means": "The hotel's pricing engine is set to win: it replaces a price sent here at its next hourly update."
252
+ },
253
+ {
254
+ "code": "ENGINE_WILL_RECOUNT",
255
+ "level": "warning",
256
+ "on": "availability",
257
+ "means": "The hotel publishes the count its bookings work out: a count above 0 sent here is replaced. A 0 holds."
258
+ },
259
+ {
260
+ "code": "DRIFT_REPAIR_OFF",
261
+ "level": "info",
262
+ "on": "rates, restrictions",
263
+ "means": "The hotel switched the nightly repair off: a value changed on the channel manager's side is reported, not sent again."
264
+ }
265
+ ];
266
+ /** The three levels of a support ticket (`zs.supportTickets.create`): what each means and when ZimmerStack first replies. */
267
+ export const SUPPORT_SEVERITIES = [
268
+ {
269
+ "severity": "many_hotels",
270
+ "name": "Many hotels",
271
+ "means": "2 or more of your hotels, or all of them, cannot take bookings or cannot send prices and rooms to the booking sites.",
272
+ "firstReply": "Within 60 minutes, 9:00 to 21:00 IST, every day. Opened outside those hours: by 10:00 IST."
273
+ },
274
+ {
275
+ "severity": "one_hotel",
276
+ "name": "One hotel",
277
+ "means": "One hotel cannot take bookings or cannot send prices and rooms to the booking sites.",
278
+ "firstReply": "Within one working day."
279
+ },
280
+ {
281
+ "severity": "question",
282
+ "name": "Question",
283
+ "means": "Anything else: how something works, a bill, a change you plan, a problem that stops nothing.",
284
+ "firstReply": "Within one working day."
285
+ }
286
+ ];
117
287
  /** idempotent: the server replays the stored answer when the idempotency key repeats, so the client may resend the request after a network failure. */
118
288
  export const OPERATIONS = {
119
289
  "GET /properties": { idempotent: false, bodyRequired: false },
120
290
  "POST /properties": { idempotent: true, bodyRequired: true },
291
+ "PATCH /properties/{propertyId}": { idempotent: true, bodyRequired: true },
121
292
  "DELETE /properties/{propertyId}": { idempotent: false, bodyRequired: false },
122
293
  "GET /property": { idempotent: false, bodyRequired: false },
294
+ "GET /limits": { idempotent: false, bodyRequired: false },
123
295
  "GET /catalog": { idempotent: false, bodyRequired: false },
124
296
  "PUT /catalog/room-types": { idempotent: true, bodyRequired: true },
125
297
  "DELETE /catalog/room-types/{roomTypeId}": { idempotent: false, bodyRequired: false },
@@ -131,22 +303,64 @@ export const OPERATIONS = {
131
303
  "PUT /rates": { idempotent: true, bodyRequired: true },
132
304
  "GET /restrictions": { idempotent: false, bodyRequired: false },
133
305
  "PUT /restrictions": { idempotent: true, bodyRequired: true },
306
+ "POST /availability/close": { idempotent: true, bodyRequired: true },
307
+ "POST /availability/reopen": { idempotent: true, bodyRequired: true },
308
+ "GET /explain": { idempotent: false, bodyRequired: false },
309
+ "GET /sandbox/faults": { idempotent: false, bodyRequired: false },
310
+ "POST /sandbox/faults": { idempotent: true, bodyRequired: true },
311
+ "DELETE /sandbox/faults": { idempotent: false, bodyRequired: false },
134
312
  "GET /sync": { idempotent: false, bodyRequired: false },
135
313
  "GET /bookings": { idempotent: false, bodyRequired: false },
136
314
  "POST /bookings": { idempotent: true, bodyRequired: true },
137
315
  "GET /bookings/{bookingId}": { idempotent: false, bodyRequired: false },
138
- "POST /bookings/{bookingId}/cancel": { idempotent: false, bodyRequired: false },
316
+ "POST /bookings/{bookingId}/cancel": { idempotent: true, bodyRequired: false },
317
+ "GET /requests": { idempotent: false, bodyRequired: false },
139
318
  "GET /channels": { idempotent: false, bodyRequired: false },
140
319
  "PUT /channels/{channelId}/modifier": { idempotent: true, bodyRequired: true },
141
320
  "POST /rates/resend": { idempotent: true, bodyRequired: false },
142
321
  "GET /channel-bookings": { idempotent: false, bodyRequired: false },
143
322
  "GET /channel-bookings/{bookingId}": { idempotent: false, bodyRequired: false },
323
+ "GET /webhook-endpoints": { idempotent: false, bodyRequired: false },
324
+ "POST /webhook-endpoints": { idempotent: true, bodyRequired: true },
325
+ "GET /webhook-endpoints/{endpointId}": { idempotent: false, bodyRequired: false },
326
+ "PATCH /webhook-endpoints/{endpointId}": { idempotent: true, bodyRequired: true },
327
+ "DELETE /webhook-endpoints/{endpointId}": { idempotent: false, bodyRequired: false },
328
+ "POST /webhook-endpoints/{endpointId}/pause": { idempotent: true, bodyRequired: false },
329
+ "POST /webhook-endpoints/{endpointId}/resume": { idempotent: true, bodyRequired: false },
330
+ "POST /webhook-endpoints/{endpointId}/rotate-secret": { idempotent: true, bodyRequired: false },
331
+ "POST /webhook-endpoints/{endpointId}/test": { idempotent: true, bodyRequired: false },
332
+ "POST /webhook-endpoints/{endpointId}/recover": { idempotent: true, bodyRequired: true },
333
+ "GET /webhook-endpoints/{endpointId}/deliveries": { idempotent: false, bodyRequired: false },
334
+ "GET /webhook-endpoints/{endpointId}/deliveries/{deliveryId}": { idempotent: false, bodyRequired: false },
335
+ "POST /webhook-endpoints/{endpointId}/deliveries/{deliveryId}/redeliver": { idempotent: true, bodyRequired: false },
336
+ "GET /status": { idempotent: false, bodyRequired: false },
337
+ "GET /billing": { idempotent: false, bodyRequired: false },
338
+ "GET /billing/invoices": { idempotent: false, bodyRequired: false },
339
+ "GET /billing/next-invoice": { idempotent: false, bodyRequired: false },
340
+ "GET /support-tickets": { idempotent: false, bodyRequired: false },
341
+ "POST /support-tickets": { idempotent: true, bodyRequired: true },
342
+ "GET /support-tickets/{ticketId}": { idempotent: false, bodyRequired: false },
343
+ "POST /support-tickets/{ticketId}/messages": { idempotent: true, bodyRequired: true },
344
+ "POST /support-tickets/{ticketId}/close": { idempotent: true, bodyRequired: false },
345
+ "POST /sandbox/bookings/{bookingId}/no-show": { idempotent: true, bodyRequired: false },
346
+ "POST /sandbox/sync-events": { idempotent: true, bodyRequired: true },
347
+ "GET /events": { idempotent: false, bodyRequired: false },
144
348
  "GET /direct-bookings": { idempotent: false, bodyRequired: false },
145
349
  "GET /direct-bookings/{bookingId}": { idempotent: false, bodyRequired: false },
146
350
  "POST /direct-bookings/{bookingId}/cancel": { idempotent: true, bodyRequired: false },
147
351
  "GET /sandbox/bookings": { idempotent: false, bodyRequired: false },
148
352
  "POST /sandbox/bookings": { idempotent: true, bodyRequired: true },
149
- "POST /sandbox/bookings/{bookingId}/cancel": { idempotent: false, bodyRequired: false },
150
- "POST /sandbox/bookings/{bookingId}/modify": { idempotent: false, bodyRequired: true },
353
+ "POST /sandbox/bookings/{bookingId}/cancel": { idempotent: true, bodyRequired: false },
354
+ "POST /sandbox/bookings/{bookingId}/modify": { idempotent: true, bodyRequired: true },
151
355
  "GET /batches/{batchId}": { idempotent: false, bodyRequired: false },
356
+ "GET /connect-links": { idempotent: false, bodyRequired: false },
357
+ "POST /connect-links": { idempotent: true, bodyRequired: true },
358
+ "GET /connect-links/{linkId}": { idempotent: false, bodyRequired: false },
359
+ "POST /connect-links/{linkId}/revoke": { idempotent: true, bodyRequired: false },
360
+ "GET /readiness": { idempotent: false, bodyRequired: false },
361
+ "POST /go-live": { idempotent: true, bodyRequired: false },
362
+ "GET /properties/{propertyId}/keys": { idempotent: false, bodyRequired: false },
363
+ "POST /properties/{propertyId}/keys": { idempotent: true, bodyRequired: true },
364
+ "POST /properties/{propertyId}/keys/{keyId}/rotate": { idempotent: true, bodyRequired: false },
365
+ "POST /properties/{propertyId}/keys/{keyId}/revoke": { idempotent: true, bodyRequired: true },
152
366
  };
@@ -39,7 +39,7 @@ export interface GridEdits {
39
39
  date: string;
40
40
  available: number;
41
41
  }>;
42
- /** `rate` in MAJOR units. To close a night send `stopSell`, never a zero price. */
42
+ /** `rate` in MAJOR units. `stopSell` closes one rate plan on a night; 0 rooms in `availability` closes the room type. Never a zero price. */
43
43
  rates?: Array<{
44
44
  ratePlanId: number;
45
45
  date: string;
@@ -84,6 +84,11 @@ export declare function toRanges<V>(cells: ReadonlyArray<{
84
84
  date: string;
85
85
  value: V;
86
86
  }>): Array<Range<V>>;
87
+ /** How many cells (one row on one night) a list of updates names: what the API's cells budget counts. */
88
+ export declare function cellsOf(updates: ReadonlyArray<{
89
+ dateFrom: string;
90
+ dateTo: string;
91
+ }>): number;
87
92
  /**
88
93
  * Split updates so one request stays inside what the API takes: at most 1,000 updates and 5,000 cells
89
94
  * (a cell is one row on one night). A single update larger than a request is cut into shorter ranges.
package/dist/esm/grid.js CHANGED
@@ -82,6 +82,13 @@ function stable(value) {
82
82
  return JSON.stringify(entries);
83
83
  }
84
84
  const nights = (range) => Math.max(1, Math.round((ms(range.dateTo) - ms(range.dateFrom)) / DAY) + 1);
85
+ /** How many cells (one row on one night) a list of updates names: what the API's cells budget counts. */
86
+ export function cellsOf(updates) {
87
+ let cells = 0;
88
+ for (const update of updates)
89
+ cells += nights(update);
90
+ return cells;
91
+ }
85
92
  /**
86
93
  * Split updates so one request stays inside what the API takes: at most 1,000 updates and 5,000 cells
87
94
  * (a cell is one row on one night). A single update larger than a request is cut into shorter ranges.
@@ -5,12 +5,21 @@
5
5
  * mobile app, a repository or a log line.
6
6
  */
7
7
  export { ZimmerStack } from "./client.js";
8
- export type { ClientEvent, RatePlanInput, ReadOptions, RequestArgs, RoomTypeInput, StructureSaved, WriteOptions, ZimmerStackOptions } from "./client.js";
8
+ export type { ClientEvent, CloseDone, ClosePreview, CloseRequest, LimitNow, LimitsNow, RatePlanInput, ReadOptions, ReopenRequest, RequestArgs, RoomTypeInput, StructureSaved, WriteOptions, ZimmerStackOptions } from "./client.js";
9
+ export { diagnose, formatDoctorReport } from "./doctor.js";
10
+ export type { DoctorBudget, DoctorCheck, DoctorFinding, DoctorOptions, DoctorReport } from "./doctor.js";
9
11
  export { ZimmerStackError, ZimmerStackUsageError } from "./errors.js";
10
12
  export type { LocalErrorCode } from "./errors.js";
11
- export { addDays, buildGrid, channelPrice, chunk, eachDate, toRanges } from "./grid.js";
13
+ export { addDays, buildGrid, cellsOf, channelPrice, chunk, eachDate, toRanges } from "./grid.js";
12
14
  export type { Grid, GridEdits, ModifierStep, Range, Restrictions } from "./grid.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
- export { ERROR_CODES, LIMITS, MODIFIER_TAKES_EFFECT, SCOPES, SDK_VERSION } from "./generated.js";
15
+ export { checkKey } from "./key.js";
16
+ export type { KeyCheck } from "./key.js";
17
+ export { findNotice, isWritePreview, noticeMeaning, noticesOf, noticesOmittedFrom, warningsOf } from "./notices.js";
18
+ export type { NoticeCarrier } from "./notices.js";
19
+ export { shownOnce, withoutShownOnce, ZimmerStackShownOnceError } from "./shownOnce.js";
20
+ export type { ShownOnceAnswer, ShownOnceKind } from "./shownOnce.js";
21
+ export { addAmounts, amountFromHundredths, amountFromMinorUnits, amountToMinorUnits, compareAmounts, formatAmount, multiplyAmount, subtractAmounts, toAmount } from "./money.js";
22
+ export { BOOKING_EVENT_TYPES, CONNECT_EVENT_TYPES, DRIFT_EVENT_TYPES, INCIDENT_EVENT_TYPES, OTA_BOOKING_EVENT_TYPES, SUPPORT_TICKET_EVENT_TYPES, SYNC_EVENT_TYPES, WEBSITE_BOOKING_EVENT_TYPES, isConnectEvent, isDriftEvent, isIncidentEvent, isOtaBookingEvent, isSupportTicketEvent, isSyncEvent, isWebsiteBookingEvent, verifyWebhook, ZimmerStackWebhookError, } from "./webhooks.js";
23
+ export type { BookingEvent, BookingEventType, ConnectEvent, ConnectEventType, DriftEvent, DriftEventType, IncidentEvent, IncidentEventType, IncidentInEvent, OtaBookingEvent, OtaBookingEventType, SupportTicketEvent, SupportTicketEventType, SyncEvent, SyncEventType, TicketInEvent, WebhookEvent, WebhookEventType, WebsiteBookingEvent, WebsiteBookingEventType, } from "./webhooks.js";
24
+ export { ERROR_CODES, LIMITS, MODIFIER_TAKES_EFFECT, NOTICES, SCOPES, SDK_VERSION, SUPPORT_SEVERITIES } from "./generated.js";
16
25
  export type * from "./generated.js";
package/dist/esm/index.js CHANGED
@@ -5,7 +5,12 @@
5
5
  * mobile app, a repository or a log line.
6
6
  */
7
7
  export { ZimmerStack } from "./client.js";
8
+ export { diagnose, formatDoctorReport } from "./doctor.js";
8
9
  export { ZimmerStackError, ZimmerStackUsageError } from "./errors.js";
9
- export { addDays, buildGrid, channelPrice, chunk, eachDate, toRanges } from "./grid.js";
10
- export { BOOKING_EVENT_TYPES, OTA_BOOKING_EVENT_TYPES, WEBSITE_BOOKING_EVENT_TYPES, isOtaBookingEvent, isWebsiteBookingEvent, verifyWebhook, ZimmerStackWebhookError } from "./webhooks.js";
11
- export { ERROR_CODES, LIMITS, MODIFIER_TAKES_EFFECT, SCOPES, SDK_VERSION } from "./generated.js";
10
+ export { addDays, buildGrid, cellsOf, channelPrice, chunk, eachDate, toRanges } from "./grid.js";
11
+ export { checkKey } from "./key.js";
12
+ export { findNotice, isWritePreview, noticeMeaning, noticesOf, noticesOmittedFrom, warningsOf } from "./notices.js";
13
+ export { shownOnce, withoutShownOnce, ZimmerStackShownOnceError } from "./shownOnce.js";
14
+ export { addAmounts, amountFromHundredths, amountFromMinorUnits, amountToMinorUnits, compareAmounts, formatAmount, multiplyAmount, subtractAmounts, toAmount } from "./money.js";
15
+ export { BOOKING_EVENT_TYPES, CONNECT_EVENT_TYPES, DRIFT_EVENT_TYPES, INCIDENT_EVENT_TYPES, OTA_BOOKING_EVENT_TYPES, SUPPORT_TICKET_EVENT_TYPES, SYNC_EVENT_TYPES, WEBSITE_BOOKING_EVENT_TYPES, isConnectEvent, isDriftEvent, isIncidentEvent, isOtaBookingEvent, isSupportTicketEvent, isSyncEvent, isWebsiteBookingEvent, verifyWebhook, ZimmerStackWebhookError, } from "./webhooks.js";
16
+ export { ERROR_CODES, LIMITS, MODIFIER_TAKES_EFFECT, NOTICES, SCOPES, SDK_VERSION, SUPPORT_SEVERITIES } from "./generated.js";
@@ -0,0 +1,39 @@
1
+ /**
2
+ * What a ZimmerStack key looks like, checked without sending it anywhere.
3
+ *
4
+ * A key made since 22 Nov 2026 is `zsk_live_` (or `zsk_test_` on a sandbox), 40 letters and digits, then
5
+ * 6 characters that are a checksum of everything before them (CRC32, written in base 62). So a key that
6
+ * was mistyped or cut short can be told from a real one offline, before any request. A key made before
7
+ * that day is the prefix and 43 characters with no checksum; it keeps working until it is rotated.
8
+ *
9
+ * The checksum is not a secret and proves nothing about who holds the key. It says only "this was made
10
+ * by ZimmerStack and not mistyped". Nothing here ever returns or prints the key itself.
11
+ */
12
+ /** The six characters a key ends in: the CRC32 of what comes before them, in base 62, zero-padded. */
13
+ export declare function keyChecksum(head: string): string;
14
+ /** What `checkKey` found. `message` is for a person and never contains the key. */
15
+ export type KeyCheck = {
16
+ ok: true;
17
+ /** "test": a sandbox key, nothing it sends reaches a booking site. "live": a real hotel. */
18
+ mode: "live" | "test";
19
+ /** "checksummed": made since 22 Nov 2026. "legacy": made before, no checksum; it works until it is rotated. */
20
+ format: "checksummed" | "legacy";
21
+ message: string;
22
+ } | {
23
+ ok: false;
24
+ mode: "live" | "test" | null;
25
+ /** empty · not-a-key (no zsk_ prefix) · wrong-length (cut short, or something extra around it) · bad-checksum (a character changed) */
26
+ problem: "empty" | "not-a-key" | "wrong-length" | "bad-checksum";
27
+ message: string;
28
+ };
29
+ /**
30
+ * Is this string a ZimmerStack key? Checked here, with no request: the key is sent nowhere.
31
+ *
32
+ * Use it where a person pastes a key (a settings screen, a deploy script), so a slip is caught at once
33
+ * and never spends a failed sign-in. It cannot say whether the key is still valid: only a request can.
34
+ *
35
+ * @example
36
+ * const check = checkKey(process.env.ZIMMERSTACK_CONNECT_KEY);
37
+ * if (!check.ok) throw new Error(check.message);
38
+ */
39
+ export declare function checkKey(key: unknown): KeyCheck;
@@ -0,0 +1,81 @@
1
+ /**
2
+ * What a ZimmerStack key looks like, checked without sending it anywhere.
3
+ *
4
+ * A key made since 22 Nov 2026 is `zsk_live_` (or `zsk_test_` on a sandbox), 40 letters and digits, then
5
+ * 6 characters that are a checksum of everything before them (CRC32, written in base 62). So a key that
6
+ * was mistyped or cut short can be told from a real one offline, before any request. A key made before
7
+ * that day is the prefix and 43 characters with no checksum; it keeps working until it is rotated.
8
+ *
9
+ * The checksum is not a secret and proves nothing about who holds the key. It says only "this was made
10
+ * by ZimmerStack and not mistyped". Nothing here ever returns or prints the key itself.
11
+ */
12
+ const LEGACY = /^zsk_(live|test)_[A-Za-z0-9_-]{43}$/;
13
+ const CHECKSUMMED = /^zsk_(live|test)_[A-Za-z0-9]{46}$/;
14
+ const PREFIX = /^zsk_(live|test)_/;
15
+ const CHECKSUM_CHARS = 6;
16
+ const BASE62 = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
17
+ let table;
18
+ /** CRC32 (IEEE, the zlib one) of a string's bytes. A key is plain ASCII, so a character is a byte. */
19
+ function crc32(text) {
20
+ table ??= Array.from({ length: 256 }, (_, n) => {
21
+ let c = n;
22
+ for (let k = 0; k < 8; k++)
23
+ c = c & 1 ? 0xedb88320 ^ (c >>> 1) : c >>> 1;
24
+ return c >>> 0;
25
+ });
26
+ let crc = 0xffffffff;
27
+ for (let i = 0; i < text.length; i++)
28
+ crc = table[(crc ^ text.charCodeAt(i)) & 0xff] ^ (crc >>> 8);
29
+ return (crc ^ 0xffffffff) >>> 0;
30
+ }
31
+ /** The six characters a key ends in: the CRC32 of what comes before them, in base 62, zero-padded. */
32
+ export function keyChecksum(head) {
33
+ let n = crc32(head);
34
+ let out = "";
35
+ while (n > 0) {
36
+ out = BASE62[n % 62] + out;
37
+ n = Math.floor(n / 62);
38
+ }
39
+ return out.padStart(CHECKSUM_CHARS, "0");
40
+ }
41
+ /**
42
+ * Is this string a ZimmerStack key? Checked here, with no request: the key is sent nowhere.
43
+ *
44
+ * Use it where a person pastes a key (a settings screen, a deploy script), so a slip is caught at once
45
+ * and never spends a failed sign-in. It cannot say whether the key is still valid: only a request can.
46
+ *
47
+ * @example
48
+ * const check = checkKey(process.env.ZIMMERSTACK_CONNECT_KEY);
49
+ * if (!check.ok) throw new Error(check.message);
50
+ */
51
+ export function checkKey(key) {
52
+ const value = typeof key === "string" ? key.trim() : "";
53
+ if (!value)
54
+ return { ok: false, mode: null, problem: "empty", message: "No key was given. A ZimmerStack key starts with zsk_test_ (a sandbox) or zsk_live_." };
55
+ const prefix = PREFIX.exec(value);
56
+ if (!prefix) {
57
+ return { ok: false, mode: null, problem: "not-a-key", message: "This is not a ZimmerStack key: one starts with zsk_test_ (a sandbox) or zsk_live_ (a real hotel)." };
58
+ }
59
+ const mode = prefix[1];
60
+ const what = mode === "test" ? "a sandbox key (zsk_test_)" : "a live key (zsk_live_)";
61
+ if (CHECKSUMMED.test(value)) {
62
+ if (keyChecksum(value.slice(0, -CHECKSUM_CHARS)) === value.slice(-CHECKSUM_CHARS))
63
+ return { ok: true, mode, format: "checksummed", message: `This is ${what}, and its checksum holds.` };
64
+ return {
65
+ ok: false,
66
+ mode,
67
+ problem: "bad-checksum",
68
+ message: "The key's last six characters are a checksum of the rest, and they do not match: a character was mistyped or changed. Copy the whole key again from where it was shown.",
69
+ };
70
+ }
71
+ if (LEGACY.test(value)) {
72
+ return { ok: true, mode, format: "legacy", message: `This is ${what} in the format used before 22 Nov 2026. It keeps working; rotating it gives you a key whose typing slips are caught before they are sent.` };
73
+ }
74
+ const length = value.length - prefix[0].length;
75
+ return {
76
+ ok: false,
77
+ mode,
78
+ problem: "wrong-length",
79
+ message: `This starts like a ZimmerStack key but is not one: after the prefix a key has 46 letters and digits (43 characters on a key made before 22 Nov 2026), and this one has ${length}${/[^A-Za-z0-9_-]/.test(value.slice(prefix[0].length)) ? ", with a character a key never contains" : ""}. It was cut short, or something was copied with it (a quote, a space, a line break).`,
80
+ };
81
+ }
@@ -1,26 +1,40 @@
1
1
  #!/usr/bin/env node
2
+ import { diagnose, formatDoctorReport } from "../doctor.js";
2
3
  import { SDK_VERSION } from "../generated.js";
3
4
  import { findKey } from "./key.js";
4
5
  import { createMcpServer } from "./server.js";
5
6
  /**
6
- * The package's command line. One command: `mcp`, the MCP server on stdin and stdout, for a
7
- * developer's coding agent (Claude Code, Cursor, …):
7
+ * The package's command line. Two commands:
8
8
  *
9
- * npx -y @zimmerstack/connect mcp
9
+ * npx @zimmerstack/connect doctor one look at an integration when something is wrong
10
+ * npx -y @zimmerstack/connect mcp the MCP server on stdin and stdout, for a coding agent
10
11
  *
11
- * stdout carries protocol messages and nothing else; anything for a person goes to stderr.
12
+ * The MCP server's stdout carries protocol messages and nothing else; anything for a person goes to
13
+ * stderr. The doctor prints its report to stdout and never prints the key.
12
14
  */
13
15
  const KEY_ENV = "ZIMMERSTACK_CONNECT_KEY";
14
16
  const HELP = `@zimmerstack/connect ${SDK_VERSION}
15
17
 
18
+ zimmerstack-connect doctor Check an integration: the key, whether something is wrong on
19
+ ZimmerStack's side, the hotels and scopes the key reaches (and what a
20
+ hotel that is not live yet still needs), every budget, the last day's
21
+ refused requests, the webhook endpoints, sync and drift. Reads only;
22
+ works with a test key and a live key.
23
+ --property <id> A company key: look at this hotel (default: the first five).
24
+ --room-type <id> --night <YYYY-MM-DD>
25
+ Also explain that night of that room type: what your software last
26
+ sent, what ZimmerStack's record holds, what the channel manager was
27
+ last seen holding. Add --rate-plan <id> for one rate plan only.
28
+ --json The report as JSON, for a script.
16
29
  zimmerstack-connect mcp Start the MCP server for a coding agent (stdin/stdout).
17
30
  zimmerstack-connect --version
18
31
  zimmerstack-connect --help
19
32
 
20
- The MCP server gives an agent the rules for building on the ZimmerStack Connect API, a
21
- reference generated from the API's contract, and calls on a SANDBOX. It reads the sandbox key
22
- (zsk_test_…) from ${KEY_ENV}, in the environment or in the project's .env.local or
23
- .env, and refuses a live key. Add it to an agent's MCP settings as:
33
+ Both read the key from ${KEY_ENV}, in the environment or in the project's .env.local or
34
+ .env. The doctor exits 0 when nothing needs attention and 1 when something does; it never prints the
35
+ key. The MCP server gives an agent the rules for building on the ZimmerStack Connect API, a reference
36
+ generated from the API's contract, and calls on a SANDBOX: it uses a sandbox key (zsk_test_…) and
37
+ refuses a live one. Add it to an agent's MCP settings as:
24
38
 
25
39
  { "command": "npx", "args": ["-y", "@zimmerstack/connect", "mcp"] }
26
40
  `;
@@ -31,9 +45,14 @@ function serve() {
31
45
  process.stderr.write(`zimmerstack-connect mcp ${SDK_VERSION} ready (${state})\n`);
32
46
  let pending = 0;
33
47
  let ended = false;
48
+ let exiting = false;
49
+ // Exit only once stdout has handed every answer to the OS: on a pipe Node may still be writing a long answer
50
+ // (on macOS pipe writes are asynchronous), and exiting at once cut it short (seen in the smoke run, 24 Nov 2026).
34
51
  const done = () => {
35
- if (ended && pending === 0)
36
- process.exit(0);
52
+ if (!ended || pending !== 0 || exiting)
53
+ return;
54
+ exiting = true;
55
+ process.stdout.write("", () => process.exit(0));
37
56
  };
38
57
  const write = (answer) => {
39
58
  if (answer !== undefined)
@@ -75,9 +94,74 @@ function serve() {
75
94
  done();
76
95
  });
77
96
  }
78
- const [command] = process.argv.slice(2);
97
+ /**
98
+ * `doctor [--property <id>] [--room-type <id> --night <YYYY-MM-DD> [--rate-plan <id>]] [--json]`: the checks
99
+ * of src/doctor.ts, printed. Exit 0: nothing needs attention; 1: something does; 2: the command was not understood.
100
+ */
101
+ async function doctor(args) {
102
+ let propertyId;
103
+ let roomTypeId;
104
+ let ratePlanId;
105
+ let date;
106
+ let asJson = false;
107
+ const ID_OPTIONS = { "--property": "a hotel's numeric id", "--room-type": "a room type's numeric id", "--rate-plan": "a rate plan's numeric id" };
108
+ for (let i = 0; i < args.length; i++) {
109
+ const arg = args[i];
110
+ const name = arg.includes("=") ? arg.slice(0, arg.indexOf("=")) : arg;
111
+ if (arg === "--json")
112
+ asJson = true;
113
+ else if (name in ID_OPTIONS) {
114
+ const value = arg.includes("=") ? arg.slice(arg.indexOf("=") + 1) : args[++i];
115
+ if (!value || !/^[1-9]\d*$/.test(value)) {
116
+ process.stderr.write(`${name} takes ${ID_OPTIONS[name]}\n`);
117
+ return 2;
118
+ }
119
+ if (name === "--property")
120
+ propertyId = Number(value);
121
+ else if (name === "--room-type")
122
+ roomTypeId = Number(value);
123
+ else
124
+ ratePlanId = Number(value);
125
+ }
126
+ else if (name === "--night") {
127
+ const value = arg.includes("=") ? arg.slice(arg.indexOf("=") + 1) : args[++i];
128
+ if (!value || !/^\d{4}-\d{2}-\d{2}$/.test(value)) {
129
+ process.stderr.write("--night takes a date as YYYY-MM-DD, in the hotel's own calendar\n");
130
+ return 2;
131
+ }
132
+ date = value;
133
+ }
134
+ else {
135
+ process.stderr.write(`Unknown option for doctor: ${arg}\n\n${HELP}`);
136
+ return 2;
137
+ }
138
+ }
139
+ const found = findKey(process.env, process.cwd());
140
+ // An empty key is a finding like any other: the report says where to put one. Never the environment's by accident.
141
+ if ((roomTypeId === undefined) !== (date === undefined) || (ratePlanId !== undefined && roomTypeId === undefined)) {
142
+ process.stderr.write("To explain a night, give both --room-type <id> and --night <YYYY-MM-DD>; --rate-plan <id> narrows it to one plan.\n");
143
+ return 2;
144
+ }
145
+ const night = roomTypeId !== undefined && date !== undefined ? { roomTypeId, date, ...(ratePlanId === undefined ? {} : { ratePlanId }) } : undefined;
146
+ const report = await diagnose({ apiKey: found.apiKey ?? "", propertyId, ...(night ? { night } : {}) });
147
+ if (asJson)
148
+ process.stdout.write(JSON.stringify(report, null, 2) + "\n");
149
+ else
150
+ process.stdout.write(`${formatDoctorReport(report)}\n${found.keySource ? `\nThe key was read from ${found.keySource}.\n` : ""}`);
151
+ return report.ok ? 0 : 1;
152
+ }
153
+ const [command, ...rest] = process.argv.slice(2);
79
154
  if (command === "mcp")
80
155
  serve();
156
+ else if (command === "doctor") {
157
+ doctor(rest).then((code) => {
158
+ process.exitCode = code;
159
+ }, () => {
160
+ // Whatever went wrong, the words are for a person and never the key.
161
+ process.stderr.write("The doctor stopped before it had a report. Run it again; if it repeats, write to support@zimmerstack.com.\n");
162
+ process.exitCode = 1;
163
+ });
164
+ }
81
165
  else if (command === "--version" || command === "-v")
82
166
  process.stdout.write(SDK_VERSION + "\n");
83
167
  else {