@zimmerstack/connect 0.6.0 → 0.9.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.
Files changed (51) hide show
  1. package/AGENTS.md +269 -15
  2. package/README.md +451 -18
  3. package/dist/cjs/client.d.ts +503 -13
  4. package/dist/cjs/client.js +743 -45
  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 +2921 -207
  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 +503 -13
  26. package/dist/esm/client.js +741 -45
  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 +2921 -207
  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 +88 -9
  40. package/dist/esm/mcp/reference.generated.js +4464 -974
  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 +1 -1
@@ -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.6.0";
4
+ export const SDK_VERSION = "0.9.0";
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,
@@ -60,6 +64,8 @@ export const ERROR_CODES = [
60
64
  "EXTERNAL_REFERENCE_REUSED",
61
65
  "PAYMENT_NOT_ALLOWED",
62
66
  "PAYMENT_EXCEEDS_TOTAL",
67
+ "TAXES_NOT_CONFIGURED",
68
+ "TAXES_INSIDE_RATES",
63
69
  "BOOKING_NOT_FOUND",
64
70
  "BOOKING_NOT_CANCELLABLE",
65
71
  "MODULE_NOT_ENTITLED",
@@ -69,6 +75,14 @@ export const ERROR_CODES = [
69
75
  "CATALOG_CONFLICT",
70
76
  "CATALOG_BUSY",
71
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",
72
86
  "PROPERTY_REQUIRED",
73
87
  "PROPERTY_NOT_FOUND",
74
88
  "ARI_NOT_AUTHORITATIVE",
@@ -94,7 +108,21 @@ export const ERROR_CODES = [
94
108
  "CONFIRMATION_MISMATCH",
95
109
  "PROPERTY_NOT_REMOVABLE",
96
110
  "PROPERTY_BUSY",
97
- "PRICE_UNAVAILABLE"
111
+ "PRICE_UNAVAILABLE",
112
+ "CONNECT_LINK_NOT_FOUND",
113
+ "CONNECT_LINKS_UNAVAILABLE",
114
+ "CHANNEL_NOT_AVAILABLE",
115
+ "LIVE_KEY_REQUIRED",
116
+ "NOT_READY",
117
+ "KEY_NOT_FOUND",
118
+ "KEY_LIMIT",
119
+ "KEY_REVOKED",
120
+ "KEY_ALREADY_ROTATING",
121
+ "SCOPES_INVALID",
122
+ "ALLOWED_CIDRS_INVALID",
123
+ "REASON_REQUIRED",
124
+ "SUPPORT_TICKET_NOT_FOUND",
125
+ "SUPPORT_TICKET_CLOSED"
98
126
  ];
99
127
  /** What a key may do. The hotel's owner (or, for a vendor's key, the vendor) chose them when the key was made. */
100
128
  export const SCOPES = [
@@ -108,16 +136,160 @@ export const SCOPES = [
108
136
  "bookings:read",
109
137
  "bookings:write",
110
138
  "bookings:payments",
111
- "properties:write"
139
+ "properties:write",
140
+ "webhooks:manage",
141
+ "channels:connect",
142
+ "keys:manage",
143
+ "billing:read",
144
+ "support:write"
112
145
  ];
113
146
  /** When a channel's price modifier takes effect. Show it where a person saves one. */
114
147
  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.";
148
+ /** 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. */
149
+ export const NOTICES = [
150
+ {
151
+ "code": "NOT_SOURCE_OF_TRUTH",
152
+ "level": "warning",
153
+ "on": "every write",
154
+ "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."
155
+ },
156
+ {
157
+ "code": "ROOM_TYPE_NOT_LINKED",
158
+ "level": "warning",
159
+ "on": "availability",
160
+ "means": "The room type has no link to the channel manager: its count is kept and sent nowhere."
161
+ },
162
+ {
163
+ "code": "PLAN_NOT_LINKED",
164
+ "level": "warning",
165
+ "on": "rates, restrictions",
166
+ "means": "The rate plan has no link to the channel manager: its values are kept and sent nowhere."
167
+ },
168
+ {
169
+ "code": "PLAN_NOT_MAPPED",
170
+ "level": "warning",
171
+ "on": "rates, restrictions",
172
+ "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."
173
+ },
174
+ {
175
+ "code": "ROOM_STILL_ON_SALE",
176
+ "level": "warning",
177
+ "on": "restrictions",
178
+ "means": "You stop-sold one rate plan; the room is still on sale through its other plans (otherRatePlanIds)."
179
+ },
180
+ {
181
+ "code": "OTA_LINKED_RATES_NOT_REACHED",
182
+ "level": "info",
183
+ "on": "restrictions",
184
+ "means": "A stop-sell does not reach a rate an OTA links on its own side: only the room's count closes it."
185
+ },
186
+ {
187
+ "code": "STAY_RULES_FROM_ANOTHER_PLAN",
188
+ "level": "warning",
189
+ "on": "restrictions",
190
+ "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."
191
+ },
192
+ {
193
+ "code": "PER_OTA_PLANS_FOLLOW",
194
+ "level": "info",
195
+ "on": "rates, restrictions",
196
+ "means": "The plan has per-OTA plans: its price is copied onto them and they follow its stay rules."
197
+ },
198
+ {
199
+ "code": "PER_OTA_PLAN_FOLLOWS_PARENT",
200
+ "level": "warning",
201
+ "on": "rates, restrictions",
202
+ "means": "The plan you wrote is a per-OTA plan: its parent's price and stay rules replace what is set here."
203
+ },
204
+ {
205
+ "code": "VALUE_HELD",
206
+ "level": "warning",
207
+ "on": "rates, restrictions",
208
+ "means": "The value equals one the channel manager refused: it is held with its words, not sent again."
209
+ },
210
+ {
211
+ "code": "COUNT_WAS_REFUSED",
212
+ "level": "warning",
213
+ "on": "availability",
214
+ "means": "The last count sent for these nights was refused by the channel manager and nothing has landed since."
215
+ },
216
+ {
217
+ "code": "COUNT_ZERO_IS_NOT_STOP_SELL",
218
+ "level": "info",
219
+ "on": "availability",
220
+ "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."
221
+ },
222
+ {
223
+ "code": "STOP_SELL_IS_NOT_A_COUNT",
224
+ "level": "info",
225
+ "on": "restrictions",
226
+ "means": "You sent a stop-sell: a switch on those plans. The room's count is untouched."
227
+ },
228
+ {
229
+ "code": "COUNT_OPEN_BUT_PLANS_STOPPED",
230
+ "level": "warning",
231
+ "on": "availability",
232
+ "means": "You sent a count above 0 for nights on which every plan of the room is stop-sold: the room does not sell."
233
+ },
234
+ {
235
+ "code": "NEW_DATES_OPEN_CLOSED",
236
+ "level": "warning",
237
+ "on": "availability",
238
+ "means": "The hotel's rule \"new dates open closed\" will set these nights to 0 when they come on sale."
239
+ },
240
+ {
241
+ "code": "FAR_NIGHTS_NEED_A_COUNT",
242
+ "level": "warning",
243
+ "on": "rates, restrictions",
244
+ "means": "A night past day 365 with no count of its own goes out closed, whatever its price or stay rules."
245
+ },
246
+ {
247
+ "code": "ENGINE_WILL_REPRICE",
248
+ "level": "warning",
249
+ "on": "rates",
250
+ "means": "The hotel's pricing engine is set to win: it replaces a price sent here at its next hourly update."
251
+ },
252
+ {
253
+ "code": "ENGINE_WILL_RECOUNT",
254
+ "level": "warning",
255
+ "on": "availability",
256
+ "means": "The hotel publishes the count its bookings work out: a count above 0 sent here is replaced. A 0 holds."
257
+ },
258
+ {
259
+ "code": "DRIFT_REPAIR_OFF",
260
+ "level": "info",
261
+ "on": "rates, restrictions",
262
+ "means": "The hotel switched the nightly repair off: a value changed on the channel manager's side is reported, not sent again."
263
+ }
264
+ ];
265
+ /** The three levels of a support ticket (`zs.supportTickets.create`): what each means and when ZimmerStack first replies. */
266
+ export const SUPPORT_SEVERITIES = [
267
+ {
268
+ "severity": "many_hotels",
269
+ "name": "Many hotels",
270
+ "means": "2 or more of your hotels, or all of them, cannot take bookings or cannot send prices and rooms to the booking sites.",
271
+ "firstReply": "Within 60 minutes, 9:00 to 21:00 IST, every day. Opened outside those hours: by 10:00 IST."
272
+ },
273
+ {
274
+ "severity": "one_hotel",
275
+ "name": "One hotel",
276
+ "means": "One hotel cannot take bookings or cannot send prices and rooms to the booking sites.",
277
+ "firstReply": "Within one working day."
278
+ },
279
+ {
280
+ "severity": "question",
281
+ "name": "Question",
282
+ "means": "Anything else: how something works, a bill, a change you plan, a problem that stops nothing.",
283
+ "firstReply": "Within one working day."
284
+ }
285
+ ];
115
286
  /** idempotent: the server replays the stored answer when the idempotency key repeats, so the client may resend the request after a network failure. */
116
287
  export const OPERATIONS = {
117
288
  "GET /properties": { idempotent: false, bodyRequired: false },
118
289
  "POST /properties": { idempotent: true, bodyRequired: true },
119
290
  "DELETE /properties/{propertyId}": { idempotent: false, bodyRequired: false },
120
291
  "GET /property": { idempotent: false, bodyRequired: false },
292
+ "GET /limits": { idempotent: false, bodyRequired: false },
121
293
  "GET /catalog": { idempotent: false, bodyRequired: false },
122
294
  "PUT /catalog/room-types": { idempotent: true, bodyRequired: true },
123
295
  "DELETE /catalog/room-types/{roomTypeId}": { idempotent: false, bodyRequired: false },
@@ -129,22 +301,64 @@ export const OPERATIONS = {
129
301
  "PUT /rates": { idempotent: true, bodyRequired: true },
130
302
  "GET /restrictions": { idempotent: false, bodyRequired: false },
131
303
  "PUT /restrictions": { idempotent: true, bodyRequired: true },
304
+ "POST /availability/close": { idempotent: true, bodyRequired: true },
305
+ "POST /availability/reopen": { idempotent: true, bodyRequired: true },
306
+ "GET /explain": { idempotent: false, bodyRequired: false },
307
+ "GET /sandbox/faults": { idempotent: false, bodyRequired: false },
308
+ "POST /sandbox/faults": { idempotent: true, bodyRequired: true },
309
+ "DELETE /sandbox/faults": { idempotent: false, bodyRequired: false },
132
310
  "GET /sync": { idempotent: false, bodyRequired: false },
133
311
  "GET /bookings": { idempotent: false, bodyRequired: false },
134
312
  "POST /bookings": { idempotent: true, bodyRequired: true },
135
313
  "GET /bookings/{bookingId}": { idempotent: false, bodyRequired: false },
136
- "POST /bookings/{bookingId}/cancel": { idempotent: false, bodyRequired: false },
314
+ "POST /bookings/{bookingId}/cancel": { idempotent: true, bodyRequired: false },
315
+ "GET /requests": { idempotent: false, bodyRequired: false },
137
316
  "GET /channels": { idempotent: false, bodyRequired: false },
138
317
  "PUT /channels/{channelId}/modifier": { idempotent: true, bodyRequired: true },
139
318
  "POST /rates/resend": { idempotent: true, bodyRequired: false },
140
319
  "GET /channel-bookings": { idempotent: false, bodyRequired: false },
141
320
  "GET /channel-bookings/{bookingId}": { idempotent: false, bodyRequired: false },
321
+ "GET /webhook-endpoints": { idempotent: false, bodyRequired: false },
322
+ "POST /webhook-endpoints": { idempotent: true, bodyRequired: true },
323
+ "GET /webhook-endpoints/{endpointId}": { idempotent: false, bodyRequired: false },
324
+ "PATCH /webhook-endpoints/{endpointId}": { idempotent: true, bodyRequired: true },
325
+ "DELETE /webhook-endpoints/{endpointId}": { idempotent: false, bodyRequired: false },
326
+ "POST /webhook-endpoints/{endpointId}/pause": { idempotent: true, bodyRequired: false },
327
+ "POST /webhook-endpoints/{endpointId}/resume": { idempotent: true, bodyRequired: false },
328
+ "POST /webhook-endpoints/{endpointId}/rotate-secret": { idempotent: true, bodyRequired: false },
329
+ "POST /webhook-endpoints/{endpointId}/test": { idempotent: true, bodyRequired: false },
330
+ "POST /webhook-endpoints/{endpointId}/recover": { idempotent: true, bodyRequired: true },
331
+ "GET /webhook-endpoints/{endpointId}/deliveries": { idempotent: false, bodyRequired: false },
332
+ "GET /webhook-endpoints/{endpointId}/deliveries/{deliveryId}": { idempotent: false, bodyRequired: false },
333
+ "POST /webhook-endpoints/{endpointId}/deliveries/{deliveryId}/redeliver": { idempotent: true, bodyRequired: false },
334
+ "GET /status": { idempotent: false, bodyRequired: false },
335
+ "GET /billing": { idempotent: false, bodyRequired: false },
336
+ "GET /billing/invoices": { idempotent: false, bodyRequired: false },
337
+ "GET /billing/next-invoice": { idempotent: false, bodyRequired: false },
338
+ "GET /support-tickets": { idempotent: false, bodyRequired: false },
339
+ "POST /support-tickets": { idempotent: true, bodyRequired: true },
340
+ "GET /support-tickets/{ticketId}": { idempotent: false, bodyRequired: false },
341
+ "POST /support-tickets/{ticketId}/messages": { idempotent: true, bodyRequired: true },
342
+ "POST /support-tickets/{ticketId}/close": { idempotent: true, bodyRequired: false },
343
+ "POST /sandbox/bookings/{bookingId}/no-show": { idempotent: true, bodyRequired: false },
344
+ "POST /sandbox/sync-events": { idempotent: true, bodyRequired: true },
345
+ "GET /events": { idempotent: false, bodyRequired: false },
142
346
  "GET /direct-bookings": { idempotent: false, bodyRequired: false },
143
347
  "GET /direct-bookings/{bookingId}": { idempotent: false, bodyRequired: false },
144
348
  "POST /direct-bookings/{bookingId}/cancel": { idempotent: true, bodyRequired: false },
145
349
  "GET /sandbox/bookings": { idempotent: false, bodyRequired: false },
146
350
  "POST /sandbox/bookings": { idempotent: true, bodyRequired: true },
147
- "POST /sandbox/bookings/{bookingId}/cancel": { idempotent: false, bodyRequired: false },
148
- "POST /sandbox/bookings/{bookingId}/modify": { idempotent: false, bodyRequired: true },
351
+ "POST /sandbox/bookings/{bookingId}/cancel": { idempotent: true, bodyRequired: false },
352
+ "POST /sandbox/bookings/{bookingId}/modify": { idempotent: true, bodyRequired: true },
149
353
  "GET /batches/{batchId}": { idempotent: false, bodyRequired: false },
354
+ "GET /connect-links": { idempotent: false, bodyRequired: false },
355
+ "POST /connect-links": { idempotent: true, bodyRequired: true },
356
+ "GET /connect-links/{linkId}": { idempotent: false, bodyRequired: false },
357
+ "POST /connect-links/{linkId}/revoke": { idempotent: true, bodyRequired: false },
358
+ "GET /readiness": { idempotent: false, bodyRequired: false },
359
+ "POST /go-live": { idempotent: true, bodyRequired: false },
360
+ "GET /properties/{propertyId}/keys": { idempotent: false, bodyRequired: false },
361
+ "POST /properties/{propertyId}/keys": { idempotent: true, bodyRequired: true },
362
+ "POST /properties/{propertyId}/keys/{keyId}/rotate": { idempotent: true, bodyRequired: false },
363
+ "POST /properties/{propertyId}/keys/{keyId}/revoke": { idempotent: true, bodyRequired: true },
150
364
  };
@@ -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
  `;
@@ -75,9 +89,74 @@ function serve() {
75
89
  done();
76
90
  });
77
91
  }
78
- const [command] = process.argv.slice(2);
92
+ /**
93
+ * `doctor [--property <id>] [--room-type <id> --night <YYYY-MM-DD> [--rate-plan <id>]] [--json]`: the checks
94
+ * of src/doctor.ts, printed. Exit 0: nothing needs attention; 1: something does; 2: the command was not understood.
95
+ */
96
+ async function doctor(args) {
97
+ let propertyId;
98
+ let roomTypeId;
99
+ let ratePlanId;
100
+ let date;
101
+ let asJson = false;
102
+ 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" };
103
+ for (let i = 0; i < args.length; i++) {
104
+ const arg = args[i];
105
+ const name = arg.includes("=") ? arg.slice(0, arg.indexOf("=")) : arg;
106
+ if (arg === "--json")
107
+ asJson = true;
108
+ else if (name in ID_OPTIONS) {
109
+ const value = arg.includes("=") ? arg.slice(arg.indexOf("=") + 1) : args[++i];
110
+ if (!value || !/^[1-9]\d*$/.test(value)) {
111
+ process.stderr.write(`${name} takes ${ID_OPTIONS[name]}\n`);
112
+ return 2;
113
+ }
114
+ if (name === "--property")
115
+ propertyId = Number(value);
116
+ else if (name === "--room-type")
117
+ roomTypeId = Number(value);
118
+ else
119
+ ratePlanId = Number(value);
120
+ }
121
+ else if (name === "--night") {
122
+ const value = arg.includes("=") ? arg.slice(arg.indexOf("=") + 1) : args[++i];
123
+ if (!value || !/^\d{4}-\d{2}-\d{2}$/.test(value)) {
124
+ process.stderr.write("--night takes a date as YYYY-MM-DD, in the hotel's own calendar\n");
125
+ return 2;
126
+ }
127
+ date = value;
128
+ }
129
+ else {
130
+ process.stderr.write(`Unknown option for doctor: ${arg}\n\n${HELP}`);
131
+ return 2;
132
+ }
133
+ }
134
+ const found = findKey(process.env, process.cwd());
135
+ // An empty key is a finding like any other: the report says where to put one. Never the environment's by accident.
136
+ if ((roomTypeId === undefined) !== (date === undefined) || (ratePlanId !== undefined && roomTypeId === undefined)) {
137
+ 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");
138
+ return 2;
139
+ }
140
+ const night = roomTypeId !== undefined && date !== undefined ? { roomTypeId, date, ...(ratePlanId === undefined ? {} : { ratePlanId }) } : undefined;
141
+ const report = await diagnose({ apiKey: found.apiKey ?? "", propertyId, ...(night ? { night } : {}) });
142
+ if (asJson)
143
+ process.stdout.write(JSON.stringify(report, null, 2) + "\n");
144
+ else
145
+ process.stdout.write(`${formatDoctorReport(report)}\n${found.keySource ? `\nThe key was read from ${found.keySource}.\n` : ""}`);
146
+ return report.ok ? 0 : 1;
147
+ }
148
+ const [command, ...rest] = process.argv.slice(2);
79
149
  if (command === "mcp")
80
150
  serve();
151
+ else if (command === "doctor") {
152
+ doctor(rest).then((code) => {
153
+ process.exitCode = code;
154
+ }, () => {
155
+ // Whatever went wrong, the words are for a person and never the key.
156
+ process.stderr.write("The doctor stopped before it had a report. Run it again; if it repeats, write to support@zimmerstack.com.\n");
157
+ process.exitCode = 1;
158
+ });
159
+ }
81
160
  else if (command === "--version" || command === "-v")
82
161
  process.stdout.write(SDK_VERSION + "\n");
83
162
  else {