@lagunacreek/hogan-pms-client 0.1.0 → 0.1.2
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/LICENSE +21 -0
- package/README.md +14 -3
- package/dist/index.cjs +198 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +956 -1
- package/dist/index.d.ts +956 -1
- package/dist/index.js +195 -1
- package/dist/index.js.map +1 -1
- package/package.json +2 -1
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Laguna Creek
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -6,7 +6,7 @@ re-implemented per service.
|
|
|
6
6
|
|
|
7
7
|
## Status
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
@wip
|
|
10
10
|
|
|
11
11
|
## Usage
|
|
12
12
|
|
|
@@ -17,6 +17,17 @@ console.log(version()); // -> "0.1.0"
|
|
|
17
17
|
console.log(VERSION); // -> "0.1.0"
|
|
18
18
|
```
|
|
19
19
|
|
|
20
|
+
Call an OTA endpoint with the internal client (constructor args: `apiKey`, `env`,
|
|
21
|
+
`version`; `env` is one of `LOCAL` | `DEV` | `TEST` | `PROD`):
|
|
22
|
+
|
|
23
|
+
```ts
|
|
24
|
+
import { HoganInternalOTAClient } from "@lagunacreek/hogan-pms-client";
|
|
25
|
+
|
|
26
|
+
const ota = new HoganInternalOTAClient(process.env.HOGAN_API_KEY!, "LOCAL", "v1");
|
|
27
|
+
const me = await ota.whoami(); // GET /ota/v1/getWhoami
|
|
28
|
+
console.log(me.tenant); // -> "DEFAULT"
|
|
29
|
+
```
|
|
30
|
+
|
|
20
31
|
## Development
|
|
21
32
|
|
|
22
33
|
```bash
|
|
@@ -32,8 +43,8 @@ npm run typecheck # tsc --noEmit
|
|
|
32
43
|
src/
|
|
33
44
|
index.ts # barrel export
|
|
34
45
|
version.ts # version() — package version
|
|
35
|
-
|
|
36
|
-
|
|
46
|
+
internal-ota.ts # Maps to Hogan Internal OTA methods
|
|
47
|
+
client.ts # (planned) HoganClient: open travel alliance methods
|
|
37
48
|
errors.ts # (planned) HoganApiError, HoganValidationError, ...
|
|
38
49
|
types/ # (planned) types per resource
|
|
39
50
|
resources/ # (planned) one file per endpoint group
|
package/dist/index.cjs
CHANGED
|
@@ -20,18 +20,215 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/index.ts
|
|
21
21
|
var index_exports = {};
|
|
22
22
|
__export(index_exports, {
|
|
23
|
+
HoganApiError: () => HoganApiError,
|
|
24
|
+
HoganInternalOTAClient: () => internal_ota_default,
|
|
25
|
+
HoganNetworkError: () => HoganNetworkError,
|
|
23
26
|
VERSION: () => VERSION,
|
|
24
27
|
version: () => version
|
|
25
28
|
});
|
|
26
29
|
module.exports = __toCommonJS(index_exports);
|
|
27
30
|
|
|
28
31
|
// src/version.ts
|
|
29
|
-
var VERSION = true ? "0.1.
|
|
32
|
+
var VERSION = true ? "0.1.2" : "0.0.0";
|
|
30
33
|
function version() {
|
|
31
34
|
return VERSION;
|
|
32
35
|
}
|
|
36
|
+
|
|
37
|
+
// src/errors.ts
|
|
38
|
+
var HoganApiError = class extends Error {
|
|
39
|
+
status;
|
|
40
|
+
statusText;
|
|
41
|
+
method;
|
|
42
|
+
url;
|
|
43
|
+
/** Parsed response body, or the raw text if it was not JSON. */
|
|
44
|
+
body;
|
|
45
|
+
constructor(args) {
|
|
46
|
+
super(
|
|
47
|
+
`Hogan API ${args.method} ${args.url} failed: ${args.status} ${args.statusText}`
|
|
48
|
+
);
|
|
49
|
+
this.name = "HoganApiError";
|
|
50
|
+
this.status = args.status;
|
|
51
|
+
this.statusText = args.statusText;
|
|
52
|
+
this.method = args.method;
|
|
53
|
+
this.url = args.url;
|
|
54
|
+
this.body = args.body;
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
var HoganNetworkError = class extends Error {
|
|
58
|
+
method;
|
|
59
|
+
url;
|
|
60
|
+
constructor(args) {
|
|
61
|
+
super(`Hogan API request to ${args.method} ${args.url} failed to send`, {
|
|
62
|
+
cause: args.cause
|
|
63
|
+
});
|
|
64
|
+
this.name = "HoganNetworkError";
|
|
65
|
+
this.method = args.method;
|
|
66
|
+
this.url = args.url;
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
// src/resources/requests.ts
|
|
71
|
+
var requestHeaders = (apiKey) => ({
|
|
72
|
+
"Content-Type": "application/json",
|
|
73
|
+
Accept: "application/json",
|
|
74
|
+
"x-api-key": `${apiKey}`
|
|
75
|
+
});
|
|
76
|
+
var parseBody = async (response) => {
|
|
77
|
+
if (response.status === 204 || response.status === 205) {
|
|
78
|
+
return void 0;
|
|
79
|
+
}
|
|
80
|
+
const text = await response.text();
|
|
81
|
+
if (text === "") {
|
|
82
|
+
return void 0;
|
|
83
|
+
}
|
|
84
|
+
try {
|
|
85
|
+
return JSON.parse(text);
|
|
86
|
+
} catch {
|
|
87
|
+
return text;
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
var request = async ({
|
|
91
|
+
method,
|
|
92
|
+
url,
|
|
93
|
+
apiKey,
|
|
94
|
+
body
|
|
95
|
+
}) => {
|
|
96
|
+
const headers = requestHeaders(apiKey);
|
|
97
|
+
let response;
|
|
98
|
+
try {
|
|
99
|
+
response = await fetch(url, {
|
|
100
|
+
method,
|
|
101
|
+
headers,
|
|
102
|
+
...body !== void 0 ? { body: JSON.stringify(body) } : {}
|
|
103
|
+
});
|
|
104
|
+
} catch (cause) {
|
|
105
|
+
throw new HoganNetworkError({ method, url, cause });
|
|
106
|
+
}
|
|
107
|
+
const parsed = await parseBody(response);
|
|
108
|
+
if (!response.ok) {
|
|
109
|
+
throw new HoganApiError({
|
|
110
|
+
status: response.status,
|
|
111
|
+
statusText: response.statusText,
|
|
112
|
+
method,
|
|
113
|
+
url,
|
|
114
|
+
body: parsed
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
return parsed;
|
|
118
|
+
};
|
|
119
|
+
var getRequest = (url, apiKey) => request({ method: "GET", url, apiKey });
|
|
120
|
+
var postRequest = (url, apiKey, body) => request({ method: "POST", url, apiKey, body });
|
|
121
|
+
|
|
122
|
+
// src/internal-ota.ts
|
|
123
|
+
var internalOta = class {
|
|
124
|
+
apiKey;
|
|
125
|
+
env;
|
|
126
|
+
version;
|
|
127
|
+
baseUrl;
|
|
128
|
+
getBaseUrl() {
|
|
129
|
+
this.env = this.env.toUpperCase();
|
|
130
|
+
switch (this.env) {
|
|
131
|
+
case "PROD":
|
|
132
|
+
case "PRODUCTION":
|
|
133
|
+
return `https://production-api.lagunacreek.cloud/ota/${this.version}`;
|
|
134
|
+
case "TEST":
|
|
135
|
+
case "TESTING":
|
|
136
|
+
return `https://testing-api.lagunacreek.net/ota/${this.version}`;
|
|
137
|
+
case "DEV":
|
|
138
|
+
case "DEVELOPMENT":
|
|
139
|
+
return `https://development-api.lagunacreek.net/ota/${this.version}`;
|
|
140
|
+
case "LOCAL":
|
|
141
|
+
default:
|
|
142
|
+
return `http://localhost:50000/ota/${this.version}`;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
constructor(apiKey = "", env = "LOCAL", version2 = "v1") {
|
|
146
|
+
this.apiKey = apiKey;
|
|
147
|
+
this.env = env;
|
|
148
|
+
this.version = version2;
|
|
149
|
+
this.baseUrl = this.getBaseUrl();
|
|
150
|
+
}
|
|
151
|
+
overrideBaseUrl(baseUrl) {
|
|
152
|
+
this.baseUrl = baseUrl;
|
|
153
|
+
}
|
|
154
|
+
setAttribute(key, value) {
|
|
155
|
+
this[`${key}`] = value;
|
|
156
|
+
}
|
|
157
|
+
getAttribute(key) {
|
|
158
|
+
return this[key];
|
|
159
|
+
}
|
|
160
|
+
async whoami() {
|
|
161
|
+
return getRequest(`${this.baseUrl}/getWhoami`, this.apiKey);
|
|
162
|
+
}
|
|
163
|
+
async getOrg() {
|
|
164
|
+
return getRequest(`${this.baseUrl}/getOrg`, this.apiKey);
|
|
165
|
+
}
|
|
166
|
+
async getProperties() {
|
|
167
|
+
return getRequest(`${this.baseUrl}/getProperties`, this.apiKey);
|
|
168
|
+
}
|
|
169
|
+
async getPropertyDetail(id) {
|
|
170
|
+
return getRequest(`${this.baseUrl}/getPropertyDetail/${id}`, this.apiKey);
|
|
171
|
+
}
|
|
172
|
+
async getAvailability(params) {
|
|
173
|
+
const query = new URLSearchParams({
|
|
174
|
+
start_date: params.start_date,
|
|
175
|
+
end_date: params.end_date,
|
|
176
|
+
number_of_guests: String(params.number_of_guests),
|
|
177
|
+
property_id: String(params.property_id)
|
|
178
|
+
});
|
|
179
|
+
return getRequest(`${this.baseUrl}/getAvailability?${query}`, this.apiKey);
|
|
180
|
+
}
|
|
181
|
+
async getPropertyAmenities(property_id) {
|
|
182
|
+
return getRequest(`${this.baseUrl}/getPropertyAmenities/${property_id}`, this.apiKey);
|
|
183
|
+
}
|
|
184
|
+
async getRoomTypes(property_id) {
|
|
185
|
+
const query = new URLSearchParams({ property_id: String(property_id) });
|
|
186
|
+
return getRequest(`${this.baseUrl}/getRoomTypes?${query}`, this.apiKey);
|
|
187
|
+
}
|
|
188
|
+
async getRoomAvailability(params) {
|
|
189
|
+
const query = new URLSearchParams({
|
|
190
|
+
start_date: params.start_date,
|
|
191
|
+
end_date: params.end_date
|
|
192
|
+
});
|
|
193
|
+
for (const id of params.room_type_ids) {
|
|
194
|
+
query.append("room_type_ids", String(id));
|
|
195
|
+
}
|
|
196
|
+
return getRequest(`${this.baseUrl}/getRoomAvailability?${query}`, this.apiKey);
|
|
197
|
+
}
|
|
198
|
+
async getCalculateStay(params) {
|
|
199
|
+
const query = new URLSearchParams({
|
|
200
|
+
check_in: params.check_in,
|
|
201
|
+
check_out: params.check_out,
|
|
202
|
+
no_of_rooms: String(params.no_of_rooms)
|
|
203
|
+
});
|
|
204
|
+
for (const id of params.room_type_ids) {
|
|
205
|
+
query.append("room_type_ids", String(id));
|
|
206
|
+
}
|
|
207
|
+
return getRequest(`${this.baseUrl}/getCalculateStay?${query}`, this.apiKey);
|
|
208
|
+
}
|
|
209
|
+
// Property maps are returned as plain-text SVG markup (media_type text/plain).
|
|
210
|
+
// getMaps concatenates every property's SVG; getMap returns one property's SVG,
|
|
211
|
+
// or undefined when the property has no map (the server replies 204).
|
|
212
|
+
async getPropertyMaps() {
|
|
213
|
+
return getRequest(`${this.baseUrl}/properties/getMaps`, this.apiKey);
|
|
214
|
+
}
|
|
215
|
+
async getPropertyMap(property_id) {
|
|
216
|
+
return getRequest(`${this.baseUrl}/properties/getMap/${property_id}`, this.apiKey);
|
|
217
|
+
}
|
|
218
|
+
async getReservation(reservation_id) {
|
|
219
|
+
const query = new URLSearchParams({ reservation_id: String(reservation_id) });
|
|
220
|
+
return getRequest(`${this.baseUrl}/getReservation?${query}`, this.apiKey);
|
|
221
|
+
}
|
|
222
|
+
async postReservation(payload) {
|
|
223
|
+
return postRequest(`${this.baseUrl}/postReservation`, this.apiKey, payload);
|
|
224
|
+
}
|
|
225
|
+
};
|
|
226
|
+
var internal_ota_default = internalOta;
|
|
33
227
|
// Annotate the CommonJS export names for ESM import in node:
|
|
34
228
|
0 && (module.exports = {
|
|
229
|
+
HoganApiError,
|
|
230
|
+
HoganInternalOTAClient,
|
|
231
|
+
HoganNetworkError,
|
|
35
232
|
VERSION,
|
|
36
233
|
version
|
|
37
234
|
});
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/version.ts"],"sourcesContent":["// Barrel export for @lagunacreek/hogan-pms-client.\n//\n// As resources, the HoganClient, auth providers and error types are added,\n// re-export them from here so consumers have a single import surface.\nexport { version, VERSION } from \"./version.js\";\n","// `__PACKAGE_VERSION__` is replaced at build time by tsup's `define` (see\n// tsup.config.ts) and by vitest's `define` during tests, both sourced from\n// package.json. The fallback keeps the value sane if the package is consumed\n// in an unexpected way where the replacement did not happen.\ndeclare const __PACKAGE_VERSION__: string | undefined;\n\n/**\n * The version of this package, as declared in its package.json.\n */\nexport const VERSION: string =\n typeof __PACKAGE_VERSION__ === \"string\" ? __PACKAGE_VERSION__ : \"0.0.0\";\n\n/**\n * Returns the version of the hogan-pms-client package.\n */\nexport function version(): string {\n return VERSION;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACSO,IAAM,UACX,OAA0C,UAAsB;AAK3D,SAAS,UAAkB;AAChC,SAAO;AACT;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/version.ts","../src/errors.ts","../src/resources/requests.ts","../src/internal-ota.ts"],"sourcesContent":["// Barrel export for @lagunacreek/hogan-pms-client.\n//\n// As resources, the HoganClient, auth providers and error types are added,\n// re-export them from here so consumers have a single import surface.\nexport { version, VERSION } from \"./version.js\";\nexport { default as HoganInternalOTAClient } from \"./internal-ota.js\";\nexport * from \"./types/internal-ota/whoami.js\";\nexport * from \"./types/internal-ota/org.js\";\nexport * from \"./types/internal-ota/property.js\";\nexport * from \"./types/internal-ota/property-detail.js\";\nexport * from \"./types/internal-ota/availability.js\";\nexport * from \"./types/internal-ota/amenity.js\";\nexport * from \"./types/internal-ota/room-type.js\";\nexport * from \"./types/internal-ota/room-availability.js\";\nexport * from \"./types/internal-ota/calculate-stay.js\";\nexport * from \"./types/internal-ota/reservation.js\";\nexport * from \"./types/internal-ota/make-reservation.js\";\nexport * from \"./errors.js\";","// `__PACKAGE_VERSION__` is replaced at build time by tsup's `define` (see\n// tsup.config.ts) and by vitest's `define` during tests, both sourced from\n// package.json. The fallback keeps the value sane if the package is consumed\n// in an unexpected way where the replacement did not happen.\ndeclare const __PACKAGE_VERSION__: string | undefined;\n\n/**\n * The version of this package, as declared in its package.json.\n */\nexport const VERSION: string =\n typeof __PACKAGE_VERSION__ === \"string\" ? __PACKAGE_VERSION__ : \"0.0.0\";\n\n/**\n * Returns the version of the hogan-pms-client package.\n */\nexport function version(): string {\n return VERSION;\n}\n","// Error types thrown by the Hogan client. Consumers can branch on these\n// with `instanceof` instead of inspecting raw responses.\n\n/**\n * Thrown when the Hogan API responds with a non-2xx status. Carries the\n * status code and the parsed body (when available) for inspection.\n */\nexport class HoganApiError extends Error {\n readonly status: number;\n readonly statusText: string;\n readonly method: string;\n readonly url: string;\n /** Parsed response body, or the raw text if it was not JSON. */\n readonly body: unknown;\n\n constructor(args: {\n status: number;\n statusText: string;\n method: string;\n url: string;\n body: unknown;\n }) {\n super(\n `Hogan API ${args.method} ${args.url} failed: ${args.status} ${args.statusText}`,\n );\n this.name = \"HoganApiError\";\n this.status = args.status;\n this.statusText = args.statusText;\n this.method = args.method;\n this.url = args.url;\n this.body = args.body;\n }\n}\n\n/**\n * Thrown when the request never produced an HTTP response at all — a network\n * failure, DNS error, timeout/abort, etc.\n */\nexport class HoganNetworkError extends Error {\n readonly method: string;\n readonly url: string;\n\n constructor(args: { method: string; url: string; cause: unknown }) {\n super(`Hogan API request to ${args.method} ${args.url} failed to send`, {\n cause: args.cause,\n });\n this.name = \"HoganNetworkError\";\n this.method = args.method;\n this.url = args.url;\n }\n}\n","/**\n * @description Utility functions for making API requests to the Hogan PMS API.\n * Each verb (GET, POST, PUT, DELETE) delegates to a single `request` helper that\n * sets the auth header, reads the response body exactly once, and converts\n * failures into typed errors:\n * - non-2xx responses throw `HoganApiError` (with status + parsed body)\n * - transport failures (DNS, offline, abort/timeout) throw `HoganNetworkError`\n */\n\nimport { HoganApiError, HoganNetworkError } from \"../errors.js\";\n\n/**\n * @description Build the headers sent on every request. Auth is the OTA\n * `x-api-key` header (the API does not use a bearer token).\n * @param apiKey string\n */\nexport const requestHeaders = (apiKey: string): Record<string, string> => ({\n \"Content-Type\": \"application/json\",\n Accept: \"application/json\",\n \"x-api-key\": `${apiKey}`,\n});\n\n/**\n * @description Core request configuration for the `request` helper.\n * @param method string - HTTP verb (GET, POST, etc.)\n * @param url string - The URL to send the request to.\n * @param apiKey string - The API key for authentication.\n * @body JSON-serialisable request body, body Omitted for GET/DELETE.\n */\ninterface RequestConfig {\n method: string;\n url: string;\n apiKey: string;\n body?: object;\n}\n\n/**\n * @description Read a fetch Response body a single time. Returns parsed JSON when\n * the body is JSON, the raw text when it is not, and `undefined` for empty/no\n * content (e.g. 204). Never throws on parse failure.\n */\nconst parseBody = async (response: Response): Promise<unknown> => {\n if (response.status === 204 || response.status === 205) {\n return undefined;\n }\n const text = await response.text();\n if (text === \"\") {\n return undefined;\n }\n try {\n return JSON.parse(text);\n } catch {\n // Error pages are sometimes plain text or HTML; hand back the raw text.\n return text;\n }\n};\n\n/**\n * @description Core request helper shared by every verb.\n * @returns Promise<T> - the parsed response body.\n * @throws HoganApiError when the server responds with a non-2xx status.\n * @throws HoganNetworkError when the request never reaches the server.\n */\nconst request = async <T>({\n method,\n url,\n apiKey,\n body,\n}: RequestConfig): Promise<T> => {\n const headers = requestHeaders(apiKey);\n\n let response: Response;\n try {\n response = await fetch(url, {\n method,\n headers,\n ...(body !== undefined ? { body: JSON.stringify(body) } : {}),\n });\n } catch (cause) {\n throw new HoganNetworkError({ method, url, cause });\n }\n\n const parsed = await parseBody(response);\n\n if (!response.ok) {\n throw new HoganApiError({\n status: response.status,\n statusText: response.statusText,\n method,\n url,\n body: parsed,\n });\n }\n\n return parsed as T;\n};\n\n/**\n * @description Make a GET request to the Hogan PMS API.\n * @param url string - The URL to send the request to.\n * @param apiKey string - The API key for authentication.\n */\nexport const getRequest = <T = unknown>(\n url: string,\n apiKey: string,\n): Promise<T> => request<T>({ method: \"GET\", url, apiKey });\n\n/**\n * @description Make a POST request to the Hogan PMS API.\n * @param url string - The URL to send the request to.\n * @param apiKey string - The API key for authentication.\n * @param body object - The data to send in the request body.\n */\nexport const postRequest = <T = unknown>(\n url: string,\n apiKey: string,\n body: object,\n): Promise<T> => request<T>({ method: \"POST\", url, apiKey, body });\n\n/**\n * @description Make a PUT request to the Hogan PMS API.\n * @param url string - The URL to send the request to.\n * @param apiKey string - The API key for authentication.\n * @param body object - The data to send in the request body.\n */\nexport const putRequest = <T = unknown>(\n url: string,\n apiKey: string,\n body: object,\n): Promise<T> => request<T>({ method: \"PUT\", url, apiKey, body });\n\n/**\n * @description Make a DELETE request to the Hogan PMS API.\n * @param url string - The URL to send the request to.\n * @param apiKey string - The API key for authentication.\n */\nexport const deleteRequest = <T = unknown>(\n url: string,\n apiKey: string,\n): Promise<T> => request<T>({ method: \"DELETE\", url, apiKey });\n","\n\nimport type { WhoAmIType } from \"./types/internal-ota/whoami\";\nimport type { orgType } from \"./types/internal-ota/org\";\nimport type { propertyDetailType } from \"./types/internal-ota/property-detail\";\nimport type { availabilityType, availabilityQueryType } from \"./types/internal-ota/availability\";\nimport type { propertyAmenityType } from \"./types/internal-ota/amenity\";\nimport type { roomTypeType } from \"./types/internal-ota/room-type\";\nimport type { roomAvailabilityType, roomAvailabilityQueryType } from \"./types/internal-ota/room-availability\";\nimport type { paymentCalculationType, calculateStayQueryType } from \"./types/internal-ota/calculate-stay\";\nimport type { ReservationDetailOutput } from \"./types/internal-ota/reservation\";\nimport type { MakeReservationPayloadOTA, MakeReservationResponse } from \"./types/internal-ota/make-reservation\";\nimport { getRequest, postRequest } from \"./resources/requests\";\n\n\nconst internalOta = class {\n\n apiKey: string;\n env: string;\n version: string;\n baseUrl: string;\n\n getBaseUrl() :string {\n this.env = this.env.toUpperCase();\n switch ( this.env ) {\n case \"PROD\":\n case \"PRODUCTION\":\n return `https://production-api.lagunacreek.cloud/ota/${this.version}`;\n case \"TEST\":\n case \"TESTING\":\n return `https://testing-api.lagunacreek.net/ota/${this.version}`;\n case \"DEV\":\n case \"DEVELOPMENT\":\n return `https://development-api.lagunacreek.net/ota/${this.version}`;\n case \"LOCAL\":\n default:\n return `http://localhost:50000/ota/${this.version}`;\n }\n }\n\n\n constructor( apiKey=\"\", env=\"LOCAL\", version=\"v1\" ) {\n this.apiKey = apiKey;\n this.env = env;\n this.version = version;\n this.baseUrl = this.getBaseUrl();\n }\n\n overrideBaseUrl( baseUrl: string ) {\n this.baseUrl = baseUrl;\n }\n\n setAttribute( key:\"apiKey\" | \"env\" | \"version\" | \"baseUrl\", value:string ) {\n this[`${key}`] = value;\n }\n\n getAttribute( key:\"apiKey\" | \"env\" | \"version\" | \"baseUrl\" ) :string {\n return this[key];\n }\n\n\n async whoami(): Promise<WhoAmIType> {\n return getRequest<WhoAmIType>( `${this.baseUrl}/getWhoami`, this.apiKey );\n }\n\n\n async getOrg(): Promise<orgType> {\n return getRequest<orgType>( `${this.baseUrl}/getOrg`, this.apiKey );\n }\n\n\n async getProperties(): Promise<orgType> {\n return getRequest<orgType>( `${this.baseUrl}/getProperties`, this.apiKey );\n }\n\n\n async getPropertyDetail( id: number | string ): Promise<propertyDetailType> {\n return getRequest<propertyDetailType>( `${this.baseUrl}/getPropertyDetail/${id}`, this.apiKey );\n }\n\n\n async getAvailability( params: availabilityQueryType ): Promise<availabilityType> {\n // rate_code is resolved server-side from the API key, so it is not sent here.\n const query = new URLSearchParams({\n start_date: params.start_date,\n end_date: params.end_date,\n number_of_guests: String( params.number_of_guests ),\n property_id: String( params.property_id ),\n });\n return getRequest<availabilityType>( `${this.baseUrl}/getAvailability?${query}`, this.apiKey );\n }\n\n\n async getPropertyAmenities( property_id: number | string ): Promise<propertyAmenityType[]> {\n return getRequest<propertyAmenityType[]>( `${this.baseUrl}/getPropertyAmenities/${property_id}`, this.apiKey );\n }\n\n\n async getRoomTypes( property_id: number | string ): Promise<roomTypeType[]> {\n const query = new URLSearchParams({ property_id: String( property_id ) });\n return getRequest<roomTypeType[]>( `${this.baseUrl}/getRoomTypes?${query}`, this.apiKey );\n }\n\n\n async getRoomAvailability( params: roomAvailabilityQueryType ): Promise<roomAvailabilityType[]> {\n const query = new URLSearchParams({\n start_date: params.start_date,\n end_date: params.end_date,\n });\n // room_type_ids is a repeated query param (?room_type_ids=1&room_type_ids=2).\n for ( const id of params.room_type_ids ) {\n query.append( \"room_type_ids\", String( id ) );\n }\n return getRequest<roomAvailabilityType[]>( `${this.baseUrl}/getRoomAvailability?${query}`, this.apiKey );\n }\n\n\n async getCalculateStay( params: calculateStayQueryType ): Promise<paymentCalculationType> {\n // rate_code is resolved server-side from the API key, so it is not sent here.\n const query = new URLSearchParams({\n check_in: params.check_in,\n check_out: params.check_out,\n no_of_rooms: String( params.no_of_rooms ),\n });\n for ( const id of params.room_type_ids ) {\n query.append( \"room_type_ids\", String( id ) );\n }\n return getRequest<paymentCalculationType>( `${this.baseUrl}/getCalculateStay?${query}`, this.apiKey );\n }\n\n\n // Property maps are returned as plain-text SVG markup (media_type text/plain).\n // getMaps concatenates every property's SVG; getMap returns one property's SVG,\n // or undefined when the property has no map (the server replies 204).\n async getPropertyMaps(): Promise<string | undefined> {\n return getRequest<string | undefined>( `${this.baseUrl}/properties/getMaps`, this.apiKey );\n }\n\n\n async getPropertyMap( property_id: number | string ): Promise<string | undefined> {\n return getRequest<string | undefined>( `${this.baseUrl}/properties/getMap/${property_id}`, this.apiKey );\n }\n\n\n async getReservation( reservation_id: number ): Promise<ReservationDetailOutput> {\n const query = new URLSearchParams({ reservation_id: String( reservation_id ) });\n return getRequest<ReservationDetailOutput>( `${this.baseUrl}/getReservation?${query}`, this.apiKey );\n }\n\n\n async postReservation( payload: MakeReservationPayloadOTA ): Promise<MakeReservationResponse> {\n return postRequest<MakeReservationResponse>( `${this.baseUrl}/postReservation`, this.apiKey, payload );\n }\n\n\n};\n\nexport default internalOta;"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACSO,IAAM,UACX,OAA0C,UAAsB;AAK3D,SAAS,UAAkB;AAChC,SAAO;AACT;;;ACVO,IAAM,gBAAN,cAA4B,MAAM;AAAA,EAC9B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA;AAAA,EAEA;AAAA,EAET,YAAY,MAMT;AACD;AAAA,MACE,aAAa,KAAK,MAAM,IAAI,KAAK,GAAG,YAAY,KAAK,MAAM,IAAI,KAAK,UAAU;AAAA,IAChF;AACA,SAAK,OAAO;AACZ,SAAK,SAAS,KAAK;AACnB,SAAK,aAAa,KAAK;AACvB,SAAK,SAAS,KAAK;AACnB,SAAK,MAAM,KAAK;AAChB,SAAK,OAAO,KAAK;AAAA,EACnB;AACF;AAMO,IAAM,oBAAN,cAAgC,MAAM;AAAA,EAClC;AAAA,EACA;AAAA,EAET,YAAY,MAAuD;AACjE,UAAM,wBAAwB,KAAK,MAAM,IAAI,KAAK,GAAG,mBAAmB;AAAA,MACtE,OAAO,KAAK;AAAA,IACd,CAAC;AACD,SAAK,OAAO;AACZ,SAAK,SAAS,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