@zimmerstack/connect 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +99 -0
- package/LICENSE +21 -0
- package/README.md +225 -2
- package/dist/cjs/client.d.ts +260 -0
- package/dist/cjs/client.js +562 -0
- package/dist/cjs/errors.d.ts +46 -0
- package/dist/cjs/errors.js +51 -0
- package/dist/cjs/generated.d.ts +1153 -0
- package/dist/cjs/generated.js +135 -0
- package/dist/cjs/grid.d.ts +105 -0
- package/dist/cjs/grid.js +135 -0
- package/dist/cjs/index.d.ts +16 -0
- package/dist/cjs/index.js +30 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/webhooks.d.ts +60 -0
- package/dist/cjs/webhooks.js +103 -0
- package/dist/esm/client.d.ts +260 -0
- package/dist/esm/client.js +558 -0
- package/dist/esm/errors.d.ts +46 -0
- package/dist/esm/errors.js +46 -0
- package/dist/esm/generated.d.ts +1153 -0
- package/dist/esm/generated.js +132 -0
- package/dist/esm/grid.d.ts +105 -0
- package/dist/esm/grid.js +127 -0
- package/dist/esm/index.d.ts +16 -0
- package/dist/esm/index.js +11 -0
- package/dist/esm/mcp/cli.d.ts +2 -0
- package/dist/esm/mcp/cli.js +86 -0
- package/dist/esm/mcp/key.d.ts +9 -0
- package/dist/esm/mcp/key.js +31 -0
- package/dist/esm/mcp/reference.d.ts +11 -0
- package/dist/esm/mcp/reference.generated.d.ts +33 -0
- package/dist/esm/mcp/reference.generated.js +2084 -0
- package/dist/esm/mcp/reference.js +137 -0
- package/dist/esm/mcp/server.d.ts +29 -0
- package/dist/esm/mcp/server.js +223 -0
- package/dist/esm/webhooks.d.ts +60 -0
- package/dist/esm/webhooks.js +98 -0
- package/package.json +61 -4
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
// GENERATED by scripts/generate.mjs from the Connect API's public contract (ZimmerStack Connect API v1).
|
|
2
|
+
// Do not edit: change the contract, then run `pnpm --dir apps/connect-sdk run generate`.
|
|
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.1.0";
|
|
5
|
+
/** Where the API lives. The key is sent nowhere else. */
|
|
6
|
+
export const API_ORIGIN = "https://api.zimmerstack.com";
|
|
7
|
+
export const API_PREFIX = "/api/v1/connect-api/v1";
|
|
8
|
+
export const IDEMPOTENCY_HEADER = "x-idempotency-key";
|
|
9
|
+
/** A software vendor's company key names the hotel on every request in this header (GET /properties lists them). */
|
|
10
|
+
export const PROPERTY_HEADER = "x-zs-property";
|
|
11
|
+
/** The published limits. A property's own figures are on GET /property (limits). */
|
|
12
|
+
export const LIMITS = {
|
|
13
|
+
"requestsPerMinute": 120,
|
|
14
|
+
"writesPerMinute": 30,
|
|
15
|
+
"propertyRequestsPerMinute": 300,
|
|
16
|
+
"propertyWritesPerMinute": 60,
|
|
17
|
+
"propertyCellsPerMinute": 20000,
|
|
18
|
+
"ipRequestsPerMinute": 240,
|
|
19
|
+
"maxUpdatesPerRequest": 1000,
|
|
20
|
+
"maxCellsPerRequest": 5000,
|
|
21
|
+
"maxBodyBytes": 1048576,
|
|
22
|
+
"horizonDays": 365,
|
|
23
|
+
"bookingsPerMinute": 20,
|
|
24
|
+
"propertyBookingsPerMinute": 40,
|
|
25
|
+
"propertyBookingsPerDay": 500,
|
|
26
|
+
"companyRequestsPerMinute": 1200,
|
|
27
|
+
"maxNightsPerBooking": 90
|
|
28
|
+
};
|
|
29
|
+
/** Every stable error code (`error.code`). Messages are for people and may change; branch on these. */
|
|
30
|
+
export const ERROR_CODES = [
|
|
31
|
+
"API_KEY_INVALID",
|
|
32
|
+
"API_KEY_REVOKED",
|
|
33
|
+
"API_KEY_EXPIRED",
|
|
34
|
+
"CONNECT_API_NOT_CONFIGURED",
|
|
35
|
+
"IP_NOT_ALLOWED",
|
|
36
|
+
"SCOPE_MISSING",
|
|
37
|
+
"PROPERTY_UNAVAILABLE",
|
|
38
|
+
"CHANNEL_MANAGER_DISABLED",
|
|
39
|
+
"PMS_NOT_AVAILABLE",
|
|
40
|
+
"VALIDATION",
|
|
41
|
+
"RANGE_INVALID",
|
|
42
|
+
"HORIZON",
|
|
43
|
+
"TOO_MANY_UPDATES",
|
|
44
|
+
"TOO_MANY_CELLS",
|
|
45
|
+
"UNKNOWN_ROOM_TYPE",
|
|
46
|
+
"UNKNOWN_RATE_PLAN",
|
|
47
|
+
"CURRENCY_MISMATCH",
|
|
48
|
+
"RATE_LIMITED",
|
|
49
|
+
"NOTHING_ACCEPTED",
|
|
50
|
+
"BATCH_NOT_FOUND",
|
|
51
|
+
"IDEMPOTENCY_KEY_INVALID",
|
|
52
|
+
"IDEMPOTENCY_KEY_REUSED",
|
|
53
|
+
"IDEMPOTENCY_IN_FLIGHT",
|
|
54
|
+
"STAY_INVALID",
|
|
55
|
+
"UNKNOWN_ROOM_TYPE_FOR_PLAN",
|
|
56
|
+
"OCCUPANCY_EXCEEDED",
|
|
57
|
+
"NO_AVAILABILITY",
|
|
58
|
+
"EXTERNAL_REFERENCE_REUSED",
|
|
59
|
+
"PAYMENT_NOT_ALLOWED",
|
|
60
|
+
"PAYMENT_EXCEEDS_TOTAL",
|
|
61
|
+
"BOOKING_NOT_FOUND",
|
|
62
|
+
"BOOKING_NOT_CANCELLABLE",
|
|
63
|
+
"MODULE_NOT_ENTITLED",
|
|
64
|
+
"SANDBOX_ONLY",
|
|
65
|
+
"ROOM_TYPE_NOT_FOUND",
|
|
66
|
+
"RATE_PLAN_NOT_FOUND",
|
|
67
|
+
"CATALOG_CONFLICT",
|
|
68
|
+
"CATALOG_BUSY",
|
|
69
|
+
"CHANNEL_MANAGER_ERROR",
|
|
70
|
+
"PROPERTY_REQUIRED",
|
|
71
|
+
"PROPERTY_NOT_FOUND",
|
|
72
|
+
"ARI_NOT_AUTHORITATIVE",
|
|
73
|
+
"ROUTE_NOT_FOUND",
|
|
74
|
+
"PAYLOAD_TOO_LARGE",
|
|
75
|
+
"AUTH_BACKEND_UNAVAILABLE",
|
|
76
|
+
"BOOKING_NOT_MODIFIABLE",
|
|
77
|
+
"SANDBOX_NOT_FOUND",
|
|
78
|
+
"SANDBOX_INCOMPLETE",
|
|
79
|
+
"WRITES_FROZEN",
|
|
80
|
+
"WRITES_SUSPENDED",
|
|
81
|
+
"SHIELD_UNAVAILABLE",
|
|
82
|
+
"CATALOG_LIMIT_REACHED",
|
|
83
|
+
"TOO_MANY_NEW_ENTITIES",
|
|
84
|
+
"RATE_OUT_OF_BAND",
|
|
85
|
+
"CHANNEL_NOT_FOUND",
|
|
86
|
+
"CHANNEL_SHARED",
|
|
87
|
+
"MODIFIER_OUT_OF_BAND"
|
|
88
|
+
];
|
|
89
|
+
/** What a key may do. The hotel's owner (or, for a vendor's key, the vendor) chose them when the key was made. */
|
|
90
|
+
export const SCOPES = [
|
|
91
|
+
"ari:read",
|
|
92
|
+
"ari:write",
|
|
93
|
+
"catalog:write",
|
|
94
|
+
"channel-modifiers:write",
|
|
95
|
+
"channel-bookings:read",
|
|
96
|
+
"bookings:read",
|
|
97
|
+
"bookings:write",
|
|
98
|
+
"bookings:payments"
|
|
99
|
+
];
|
|
100
|
+
/** When a channel's price modifier takes effect. Show it where a person saves one. */
|
|
101
|
+
export const MODIFIER_TAKES_EFFECT = "A modifier applies to prices sent to the channel after the change. Prices already on the channel stay as they are until those nights are sent again.";
|
|
102
|
+
/** idempotent: the server replays the stored answer when the idempotency key repeats, so the client may resend the request after a network failure. */
|
|
103
|
+
export const OPERATIONS = {
|
|
104
|
+
"GET /properties": { idempotent: false, bodyRequired: false },
|
|
105
|
+
"GET /property": { idempotent: false, bodyRequired: false },
|
|
106
|
+
"GET /catalog": { idempotent: false, bodyRequired: false },
|
|
107
|
+
"PUT /catalog/room-types": { idempotent: true, bodyRequired: true },
|
|
108
|
+
"DELETE /catalog/room-types/{roomTypeId}": { idempotent: false, bodyRequired: false },
|
|
109
|
+
"PUT /catalog/rate-plans": { idempotent: true, bodyRequired: true },
|
|
110
|
+
"DELETE /catalog/rate-plans/{ratePlanId}": { idempotent: false, bodyRequired: false },
|
|
111
|
+
"GET /availability": { idempotent: false, bodyRequired: false },
|
|
112
|
+
"PUT /availability": { idempotent: true, bodyRequired: true },
|
|
113
|
+
"GET /rates": { idempotent: false, bodyRequired: false },
|
|
114
|
+
"PUT /rates": { idempotent: true, bodyRequired: true },
|
|
115
|
+
"GET /restrictions": { idempotent: false, bodyRequired: false },
|
|
116
|
+
"PUT /restrictions": { idempotent: true, bodyRequired: true },
|
|
117
|
+
"GET /sync": { idempotent: false, bodyRequired: false },
|
|
118
|
+
"GET /bookings": { idempotent: false, bodyRequired: false },
|
|
119
|
+
"POST /bookings": { idempotent: true, bodyRequired: true },
|
|
120
|
+
"GET /bookings/{bookingId}": { idempotent: false, bodyRequired: false },
|
|
121
|
+
"POST /bookings/{bookingId}/cancel": { idempotent: false, bodyRequired: false },
|
|
122
|
+
"GET /channels": { idempotent: false, bodyRequired: false },
|
|
123
|
+
"PUT /channels/{channelId}/modifier": { idempotent: true, bodyRequired: true },
|
|
124
|
+
"POST /rates/resend": { idempotent: true, bodyRequired: false },
|
|
125
|
+
"GET /channel-bookings": { idempotent: false, bodyRequired: false },
|
|
126
|
+
"GET /channel-bookings/{bookingId}": { idempotent: false, bodyRequired: false },
|
|
127
|
+
"GET /sandbox/bookings": { idempotent: false, bodyRequired: false },
|
|
128
|
+
"POST /sandbox/bookings": { idempotent: true, bodyRequired: true },
|
|
129
|
+
"POST /sandbox/bookings/{bookingId}/cancel": { idempotent: false, bodyRequired: false },
|
|
130
|
+
"POST /sandbox/bookings/{bookingId}/modify": { idempotent: false, bodyRequired: true },
|
|
131
|
+
"GET /batches/{batchId}": { idempotent: false, bodyRequired: false },
|
|
132
|
+
};
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { type AvailabilityRead, type Catalog, type RatesRead, type RestrictionsRead } from "./generated.js";
|
|
2
|
+
/**
|
|
3
|
+
* The rate grid as a screen wants it: rows are room types with their rate plans, columns are nights.
|
|
4
|
+
* Everything here is pure (no request, no clock), so it can be tested and reused on its own.
|
|
5
|
+
*/
|
|
6
|
+
/** The six stay rules of a rate plan on a night; null = no rule set for that field. */
|
|
7
|
+
export type Restrictions = Omit<RestrictionsRead["cells"][number], "ratePlanId" | "date">;
|
|
8
|
+
export interface Grid {
|
|
9
|
+
from: string;
|
|
10
|
+
to: string;
|
|
11
|
+
/** ISO 4217. Every price in the grid is in it. */
|
|
12
|
+
currency: string;
|
|
13
|
+
/** One column per night, YYYY-MM-DD in the hotel's own timezone. */
|
|
14
|
+
dates: string[];
|
|
15
|
+
rows: Array<{
|
|
16
|
+
roomType: {
|
|
17
|
+
id: number;
|
|
18
|
+
name: string;
|
|
19
|
+
};
|
|
20
|
+
/** date → rooms of this type left to sell */
|
|
21
|
+
available: Record<string, number>;
|
|
22
|
+
plans: Array<{
|
|
23
|
+
ratePlan: {
|
|
24
|
+
id: number;
|
|
25
|
+
name: string;
|
|
26
|
+
mealPlan: Catalog["ratePlans"][number]["mealPlan"];
|
|
27
|
+
};
|
|
28
|
+
/** date → nightly price in MAJOR units (4500 = ₹4,500.00), before any channel's modifier */
|
|
29
|
+
rate: Record<string, number>;
|
|
30
|
+
/** date → the stay rules */
|
|
31
|
+
restrictions: Record<string, Restrictions>;
|
|
32
|
+
}>;
|
|
33
|
+
}>;
|
|
34
|
+
}
|
|
35
|
+
/** What a person changed on the screen: single nights, only the ones that changed. */
|
|
36
|
+
export interface GridEdits {
|
|
37
|
+
availability?: Array<{
|
|
38
|
+
roomTypeId: number;
|
|
39
|
+
date: string;
|
|
40
|
+
available: number;
|
|
41
|
+
}>;
|
|
42
|
+
/** `rate` in MAJOR units. To close a night send `stopSell`, never a zero price. */
|
|
43
|
+
rates?: Array<{
|
|
44
|
+
ratePlanId: number;
|
|
45
|
+
date: string;
|
|
46
|
+
rate: number;
|
|
47
|
+
}>;
|
|
48
|
+
restrictions?: Array<{
|
|
49
|
+
ratePlanId: number;
|
|
50
|
+
date: string;
|
|
51
|
+
} & {
|
|
52
|
+
[K in keyof Restrictions]?: NonNullable<Restrictions[K]>;
|
|
53
|
+
}>;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Every night from `from` to `to`, both included. Dates are plain calendar strings: the arithmetic runs
|
|
57
|
+
* in UTC, so the server's timezone can never move a night.
|
|
58
|
+
*/
|
|
59
|
+
export declare function eachDate(from: string, to: string): string[];
|
|
60
|
+
/** `days` after `date` (negative goes back), as a calendar date. */
|
|
61
|
+
export declare function addDays(date: string, days: number): string;
|
|
62
|
+
/** Put the catalog and the three reads together into rows and columns. */
|
|
63
|
+
export declare function buildGrid(input: {
|
|
64
|
+
from: string;
|
|
65
|
+
to: string;
|
|
66
|
+
catalog: Catalog;
|
|
67
|
+
availability: AvailabilityRead;
|
|
68
|
+
rates: RatesRead;
|
|
69
|
+
restrictions: RestrictionsRead;
|
|
70
|
+
}): Grid;
|
|
71
|
+
export interface Range<V> {
|
|
72
|
+
id: number;
|
|
73
|
+
dateFrom: string;
|
|
74
|
+
dateTo: string;
|
|
75
|
+
value: V;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Fold single-night edits into the fewest ranges: consecutive nights of one row that carry the same
|
|
79
|
+
* value become one `{ dateFrom, dateTo }`. Thirty nights at one price are one update, not thirty. When a
|
|
80
|
+
* night is given twice, the later one wins.
|
|
81
|
+
*/
|
|
82
|
+
export declare function toRanges<V>(cells: ReadonlyArray<{
|
|
83
|
+
id: number;
|
|
84
|
+
date: string;
|
|
85
|
+
value: V;
|
|
86
|
+
}>): Array<Range<V>>;
|
|
87
|
+
/**
|
|
88
|
+
* Split updates so one request stays inside what the API takes: at most 1,000 updates and 5,000 cells
|
|
89
|
+
* (a cell is one row on one night). A single update larger than a request is cut into shorter ranges.
|
|
90
|
+
*/
|
|
91
|
+
export declare function chunk<U extends {
|
|
92
|
+
dateFrom: string;
|
|
93
|
+
dateTo: string;
|
|
94
|
+
}>(updates: readonly U[], maxUpdates?: number, maxCells?: number): U[][];
|
|
95
|
+
/** A channel's price modifier: ordered steps applied to every price sent to that channel. */
|
|
96
|
+
export type ModifierStep = {
|
|
97
|
+
action: "increase" | "decrease";
|
|
98
|
+
type: "percent" | "fixed";
|
|
99
|
+
value: number;
|
|
100
|
+
};
|
|
101
|
+
/**
|
|
102
|
+
* What a channel is sent for a price, in MAJOR units: the steps applied in order. Your grid holds the
|
|
103
|
+
* price before any modifier (that is what the API returns); use this to show "on Booking.com" beside it.
|
|
104
|
+
*/
|
|
105
|
+
export declare function channelPrice(rate: number, steps: readonly ModifierStep[]): number;
|
package/dist/esm/grid.js
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { LIMITS } from "./generated.js";
|
|
2
|
+
const DAY = 86_400_000;
|
|
3
|
+
const DATE = /^\d{4}-\d{2}-\d{2}$/;
|
|
4
|
+
function ms(date) {
|
|
5
|
+
const t = DATE.test(date) ? Date.parse(date + "T00:00:00Z") : NaN;
|
|
6
|
+
if (Number.isNaN(t))
|
|
7
|
+
throw new RangeError(`"${date}" is not a calendar date (YYYY-MM-DD)`);
|
|
8
|
+
return t;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Every night from `from` to `to`, both included. Dates are plain calendar strings: the arithmetic runs
|
|
12
|
+
* in UTC, so the server's timezone can never move a night.
|
|
13
|
+
*/
|
|
14
|
+
export function eachDate(from, to) {
|
|
15
|
+
const out = [];
|
|
16
|
+
for (let t = ms(from), end = ms(to); t <= end; t += DAY)
|
|
17
|
+
out.push(new Date(t).toISOString().slice(0, 10));
|
|
18
|
+
return out;
|
|
19
|
+
}
|
|
20
|
+
/** `days` after `date` (negative goes back), as a calendar date. */
|
|
21
|
+
export function addDays(date, days) {
|
|
22
|
+
return new Date(ms(date) + days * DAY).toISOString().slice(0, 10);
|
|
23
|
+
}
|
|
24
|
+
/** Put the catalog and the three reads together into rows and columns. */
|
|
25
|
+
export function buildGrid(input) {
|
|
26
|
+
const rows = input.catalog.roomTypes.map((roomType) => ({
|
|
27
|
+
roomType: { id: roomType.id, name: roomType.name },
|
|
28
|
+
available: {},
|
|
29
|
+
plans: input.catalog.ratePlans
|
|
30
|
+
.filter((plan) => plan.roomTypeId === roomType.id)
|
|
31
|
+
.map((plan) => ({ ratePlan: { id: plan.id, name: plan.name, mealPlan: plan.mealPlan }, rate: {}, restrictions: {} })),
|
|
32
|
+
}));
|
|
33
|
+
const rowOf = new Map(rows.map((row) => [row.roomType.id, row]));
|
|
34
|
+
const planOf = new Map(rows.flatMap((row) => row.plans.map((plan) => [plan.ratePlan.id, plan])));
|
|
35
|
+
for (const cell of input.availability.cells) {
|
|
36
|
+
const row = rowOf.get(cell.roomTypeId);
|
|
37
|
+
if (row)
|
|
38
|
+
row.available[cell.date] = cell.available;
|
|
39
|
+
}
|
|
40
|
+
for (const cell of input.rates.cells) {
|
|
41
|
+
const plan = planOf.get(cell.ratePlanId);
|
|
42
|
+
if (plan)
|
|
43
|
+
plan.rate[cell.date] = cell.rateMinor / 100; // read in minor units, shown and written in major
|
|
44
|
+
}
|
|
45
|
+
for (const { ratePlanId, date, ...rules } of input.restrictions.cells) {
|
|
46
|
+
const plan = planOf.get(ratePlanId);
|
|
47
|
+
if (plan)
|
|
48
|
+
plan.restrictions[date] = rules;
|
|
49
|
+
}
|
|
50
|
+
return { from: input.from, to: input.to, currency: input.catalog.currency, dates: eachDate(input.from, input.to), rows };
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Fold single-night edits into the fewest ranges: consecutive nights of one row that carry the same
|
|
54
|
+
* value become one `{ dateFrom, dateTo }`. Thirty nights at one price are one update, not thirty. When a
|
|
55
|
+
* night is given twice, the later one wins.
|
|
56
|
+
*/
|
|
57
|
+
export function toRanges(cells) {
|
|
58
|
+
const latest = new Map();
|
|
59
|
+
for (const cell of cells)
|
|
60
|
+
latest.set(`${cell.id}|${cell.date}`, cell);
|
|
61
|
+
const sorted = [...latest.values()].sort((a, b) => a.id - b.id || (a.date < b.date ? -1 : a.date > b.date ? 1 : 0));
|
|
62
|
+
const out = [];
|
|
63
|
+
for (const cell of sorted) {
|
|
64
|
+
const last = out[out.length - 1];
|
|
65
|
+
if (last && last.id === cell.id && same(last.value, cell.value) && ms(cell.date) - ms(last.dateTo) === DAY) {
|
|
66
|
+
last.dateTo = cell.date;
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
out.push({ id: cell.id, dateFrom: cell.date, dateTo: cell.date, value: cell.value });
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return out;
|
|
73
|
+
}
|
|
74
|
+
/** Equal values, whatever order an object's fields were written in. */
|
|
75
|
+
function same(a, b) {
|
|
76
|
+
return stable(a) === stable(b);
|
|
77
|
+
}
|
|
78
|
+
function stable(value) {
|
|
79
|
+
if (value === null || typeof value !== "object" || Array.isArray(value))
|
|
80
|
+
return JSON.stringify(value);
|
|
81
|
+
const entries = Object.entries(value).sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0));
|
|
82
|
+
return JSON.stringify(entries);
|
|
83
|
+
}
|
|
84
|
+
const nights = (range) => Math.max(1, Math.round((ms(range.dateTo) - ms(range.dateFrom)) / DAY) + 1);
|
|
85
|
+
/**
|
|
86
|
+
* Split updates so one request stays inside what the API takes: at most 1,000 updates and 5,000 cells
|
|
87
|
+
* (a cell is one row on one night). A single update larger than a request is cut into shorter ranges.
|
|
88
|
+
*/
|
|
89
|
+
export function chunk(updates, maxUpdates = LIMITS.maxUpdatesPerRequest, maxCells = LIMITS.maxCellsPerRequest) {
|
|
90
|
+
const pieces = [];
|
|
91
|
+
for (const update of updates) {
|
|
92
|
+
let from = update.dateFrom;
|
|
93
|
+
while (nights({ dateFrom: from, dateTo: update.dateTo }) > maxCells) {
|
|
94
|
+
const to = addDays(from, maxCells - 1);
|
|
95
|
+
pieces.push({ ...update, dateFrom: from, dateTo: to });
|
|
96
|
+
from = addDays(to, 1);
|
|
97
|
+
}
|
|
98
|
+
pieces.push(from === update.dateFrom ? update : { ...update, dateFrom: from });
|
|
99
|
+
}
|
|
100
|
+
const out = [];
|
|
101
|
+
let current = [];
|
|
102
|
+
let cells = 0;
|
|
103
|
+
for (const piece of pieces) {
|
|
104
|
+
if (current.length > 0 && (current.length >= maxUpdates || cells + nights(piece) > maxCells)) {
|
|
105
|
+
out.push(current);
|
|
106
|
+
current = [];
|
|
107
|
+
cells = 0;
|
|
108
|
+
}
|
|
109
|
+
current.push(piece);
|
|
110
|
+
cells += nights(piece);
|
|
111
|
+
}
|
|
112
|
+
if (current.length > 0)
|
|
113
|
+
out.push(current);
|
|
114
|
+
return out;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* What a channel is sent for a price, in MAJOR units: the steps applied in order. Your grid holds the
|
|
118
|
+
* price before any modifier (that is what the API returns); use this to show "on Booking.com" beside it.
|
|
119
|
+
*/
|
|
120
|
+
export function channelPrice(rate, steps) {
|
|
121
|
+
let minor = Math.round(rate * 100);
|
|
122
|
+
for (const step of steps) {
|
|
123
|
+
const sign = step.action === "decrease" ? -1 : 1;
|
|
124
|
+
minor = step.type === "percent" ? minor * (1 + (sign * step.value) / 100) : minor + sign * Math.round(step.value * 100);
|
|
125
|
+
}
|
|
126
|
+
return Math.round(minor) / 100;
|
|
127
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @zimmerstack/connect: the ZimmerStack Connect API from your server.
|
|
3
|
+
*
|
|
4
|
+
* Server only. The key can change a hotel's prices on every channel: it never goes to a browser, a
|
|
5
|
+
* mobile app, a repository or a log line.
|
|
6
|
+
*/
|
|
7
|
+
export { ZimmerStack } from "./client.js";
|
|
8
|
+
export type { ClientEvent, ReadOptions, RequestArgs, WriteOptions, ZimmerStackOptions } from "./client.js";
|
|
9
|
+
export { ZimmerStackError, ZimmerStackUsageError } from "./errors.js";
|
|
10
|
+
export type { LocalErrorCode } from "./errors.js";
|
|
11
|
+
export { addDays, buildGrid, channelPrice, chunk, eachDate, toRanges } from "./grid.js";
|
|
12
|
+
export type { Grid, GridEdits, ModifierStep, Range, Restrictions } from "./grid.js";
|
|
13
|
+
export { verifyWebhook, ZimmerStackWebhookError } from "./webhooks.js";
|
|
14
|
+
export type { WebhookEvent } from "./webhooks.js";
|
|
15
|
+
export { ERROR_CODES, LIMITS, MODIFIER_TAKES_EFFECT, SCOPES, SDK_VERSION } from "./generated.js";
|
|
16
|
+
export type * from "./generated.js";
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @zimmerstack/connect: the ZimmerStack Connect API from your server.
|
|
3
|
+
*
|
|
4
|
+
* Server only. The key can change a hotel's prices on every channel: it never goes to a browser, a
|
|
5
|
+
* mobile app, a repository or a log line.
|
|
6
|
+
*/
|
|
7
|
+
export { ZimmerStack } from "./client.js";
|
|
8
|
+
export { ZimmerStackError, ZimmerStackUsageError } from "./errors.js";
|
|
9
|
+
export { addDays, buildGrid, channelPrice, chunk, eachDate, toRanges } from "./grid.js";
|
|
10
|
+
export { verifyWebhook, ZimmerStackWebhookError } from "./webhooks.js";
|
|
11
|
+
export { ERROR_CODES, LIMITS, MODIFIER_TAKES_EFFECT, SCOPES, SDK_VERSION } from "./generated.js";
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { SDK_VERSION } from "../generated.js";
|
|
3
|
+
import { findKey } from "./key.js";
|
|
4
|
+
import { createMcpServer } from "./server.js";
|
|
5
|
+
/**
|
|
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, …):
|
|
8
|
+
*
|
|
9
|
+
* npx -y @zimmerstack/connect mcp
|
|
10
|
+
*
|
|
11
|
+
* stdout carries protocol messages and nothing else; anything for a person goes to stderr.
|
|
12
|
+
*/
|
|
13
|
+
const KEY_ENV = "ZIMMERSTACK_CONNECT_KEY";
|
|
14
|
+
const HELP = `@zimmerstack/connect ${SDK_VERSION}
|
|
15
|
+
|
|
16
|
+
zimmerstack-connect mcp Start the MCP server for a coding agent (stdin/stdout).
|
|
17
|
+
zimmerstack-connect --version
|
|
18
|
+
zimmerstack-connect --help
|
|
19
|
+
|
|
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:
|
|
24
|
+
|
|
25
|
+
{ "command": "npx", "args": ["-y", "@zimmerstack/connect", "mcp"] }
|
|
26
|
+
`;
|
|
27
|
+
function serve() {
|
|
28
|
+
const found = findKey(process.env, process.cwd());
|
|
29
|
+
const server = createMcpServer(found);
|
|
30
|
+
const state = !found.apiKey ? "no key found: the rules and the reference work, sandbox calls will say how to add one" : found.apiKey.startsWith("zsk_test_") ? `sandbox key from ${found.keySource}` : `the key in ${found.keySource} is not a sandbox key: sandbox calls are refused`;
|
|
31
|
+
process.stderr.write(`zimmerstack-connect mcp ${SDK_VERSION} ready (${state})\n`);
|
|
32
|
+
let pending = 0;
|
|
33
|
+
let ended = false;
|
|
34
|
+
const done = () => {
|
|
35
|
+
if (ended && pending === 0)
|
|
36
|
+
process.exit(0);
|
|
37
|
+
};
|
|
38
|
+
const write = (answer) => {
|
|
39
|
+
if (answer !== undefined)
|
|
40
|
+
process.stdout.write(JSON.stringify(answer) + "\n");
|
|
41
|
+
};
|
|
42
|
+
const answer = async (line) => {
|
|
43
|
+
pending++;
|
|
44
|
+
try {
|
|
45
|
+
let message;
|
|
46
|
+
try {
|
|
47
|
+
message = JSON.parse(line);
|
|
48
|
+
}
|
|
49
|
+
catch {
|
|
50
|
+
return write({ jsonrpc: "2.0", id: null, error: { code: -32700, message: "Parse error" } });
|
|
51
|
+
}
|
|
52
|
+
write(await server.handle(message));
|
|
53
|
+
}
|
|
54
|
+
catch {
|
|
55
|
+
write({ jsonrpc: "2.0", id: null, error: { code: -32603, message: "Internal error" } });
|
|
56
|
+
}
|
|
57
|
+
finally {
|
|
58
|
+
pending--;
|
|
59
|
+
done();
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
let buffer = "";
|
|
63
|
+
process.stdin.setEncoding("utf8");
|
|
64
|
+
process.stdin.on("data", (chunk) => {
|
|
65
|
+
buffer += chunk;
|
|
66
|
+
for (let at = buffer.indexOf("\n"); at >= 0; at = buffer.indexOf("\n")) {
|
|
67
|
+
const line = buffer.slice(0, at).trim();
|
|
68
|
+
buffer = buffer.slice(at + 1);
|
|
69
|
+
if (line)
|
|
70
|
+
void answer(line);
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
process.stdin.on("end", () => {
|
|
74
|
+
ended = true;
|
|
75
|
+
done();
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
const [command] = process.argv.slice(2);
|
|
79
|
+
if (command === "mcp")
|
|
80
|
+
serve();
|
|
81
|
+
else if (command === "--version" || command === "-v")
|
|
82
|
+
process.stdout.write(SDK_VERSION + "\n");
|
|
83
|
+
else {
|
|
84
|
+
process.stdout.write(HELP);
|
|
85
|
+
process.exitCode = command === undefined || command === "--help" || command === "-h" ? 0 : 1;
|
|
86
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The project's key, for the MCP server: the environment first, then the `.env.local` and the `.env` of
|
|
3
|
+
* the folder the agent started the server in (where a developer keeps it while building). Only where it
|
|
4
|
+
* was found is ever reported; the value is handed to the server, which uses a sandbox key and nothing else.
|
|
5
|
+
*/
|
|
6
|
+
export declare function findKey(env: Record<string, string | undefined>, cwd: string): {
|
|
7
|
+
apiKey?: string;
|
|
8
|
+
keySource?: string;
|
|
9
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
const KEY_ENV = "ZIMMERSTACK_CONNECT_KEY";
|
|
4
|
+
/**
|
|
5
|
+
* The project's key, for the MCP server: the environment first, then the `.env.local` and the `.env` of
|
|
6
|
+
* the folder the agent started the server in (where a developer keeps it while building). Only where it
|
|
7
|
+
* was found is ever reported; the value is handed to the server, which uses a sandbox key and nothing else.
|
|
8
|
+
*/
|
|
9
|
+
export function findKey(env, cwd) {
|
|
10
|
+
const fromEnv = env[KEY_ENV]?.trim();
|
|
11
|
+
if (fromEnv)
|
|
12
|
+
return { apiKey: fromEnv, keySource: "the environment" };
|
|
13
|
+
for (const file of [".env.local", ".env"]) {
|
|
14
|
+
let text;
|
|
15
|
+
try {
|
|
16
|
+
text = readFileSync(join(cwd, file), "utf8");
|
|
17
|
+
}
|
|
18
|
+
catch {
|
|
19
|
+
continue;
|
|
20
|
+
}
|
|
21
|
+
for (const line of text.split(/\r?\n/)) {
|
|
22
|
+
const match = /^\s*(?:export\s+)?ZIMMERSTACK_CONNECT_KEY\s*=\s*(.*)$/.exec(line);
|
|
23
|
+
if (!match)
|
|
24
|
+
continue;
|
|
25
|
+
const value = (match[1] ?? "").trim().replace(/\s+#.*$/, "").replace(/^(['"])(.*)\1$/, "$2").trim();
|
|
26
|
+
if (value)
|
|
27
|
+
return { apiKey: value, keySource: file };
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return {};
|
|
31
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type ReferenceOperation } from "./reference.generated.js";
|
|
2
|
+
export declare const TOPICS: string[];
|
|
3
|
+
/** An operation by its contract name ("PUT /rates", any letter case), its path alone when one method has it, or the client's call ("zs.rates.set"). */
|
|
4
|
+
export declare function findOperation(input: string): ReferenceOperation | undefined;
|
|
5
|
+
export declare function describeOperation(op: ReferenceOperation): string;
|
|
6
|
+
export declare function describeType(name: string): string | undefined;
|
|
7
|
+
export declare function describeTopic(name: string): string | undefined;
|
|
8
|
+
/** What there is to look up. */
|
|
9
|
+
export declare function referenceIndex(): string;
|
|
10
|
+
/** The operations, topics and types that mention the most words of the query, best first. */
|
|
11
|
+
export declare function searchReference(query: string): string;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/** The rules file this package ships (AGENTS.md), for the zimmerstack_rules tool. */
|
|
2
|
+
export declare const RULES: string;
|
|
3
|
+
export interface ReferenceOperation {
|
|
4
|
+
key: string;
|
|
5
|
+
summary: string;
|
|
6
|
+
description: string;
|
|
7
|
+
scope: string | null;
|
|
8
|
+
call: string;
|
|
9
|
+
path: string[];
|
|
10
|
+
query: Array<{
|
|
11
|
+
name: string;
|
|
12
|
+
required: boolean;
|
|
13
|
+
type: string;
|
|
14
|
+
description: string;
|
|
15
|
+
}>;
|
|
16
|
+
body: string | null;
|
|
17
|
+
response: string;
|
|
18
|
+
answerStatus: number[];
|
|
19
|
+
idempotent: boolean;
|
|
20
|
+
request: unknown;
|
|
21
|
+
answer: unknown;
|
|
22
|
+
refusals: Array<{
|
|
23
|
+
status: number;
|
|
24
|
+
description: string;
|
|
25
|
+
}>;
|
|
26
|
+
}
|
|
27
|
+
export declare const REFERENCE: {
|
|
28
|
+
api: string;
|
|
29
|
+
base: string;
|
|
30
|
+
operations: ReferenceOperation[];
|
|
31
|
+
types: Record<string, string>;
|
|
32
|
+
topics: Record<string, string>;
|
|
33
|
+
};
|