hospitable 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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Khanh Cao
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 ADDED
@@ -0,0 +1,214 @@
1
+ # hospitable
2
+
3
+ [![npm version](https://badge.fury.io/js/hospitable.svg)](https://www.npmjs.com/package/hospitable)
4
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)
5
+
6
+ TypeScript SDK for the [Hospitable Public API](https://developer.hospitable.com/docs/public-api-docs/). Manage short-term rental properties, reservations, calendars, guest messaging, and reviews with full type safety.
7
+
8
+ ## Features
9
+
10
+ - **Full type safety** — 100% typed request/response models, zero `any`
11
+ - **Auth** — Personal Access Token and OAuth2 (client credentials + refresh token)
12
+ - **Auto-retry** — Jittered exponential backoff for 429 and 5xx errors
13
+ - **Auto-refresh** — 401 responses silently trigger token refresh and request retry
14
+ - **Pagination** — `iter()` async generators on every resource, no cursor tracking
15
+ - **Security** — PII automatically masked in debug logs
16
+
17
+ ## Installation
18
+
19
+ ```bash
20
+ npm install hospitable
21
+ ```
22
+
23
+ ## Quick Start
24
+
25
+ ### Personal Access Token
26
+
27
+ 1. Log in to [my.hospitable.com](https://my.hospitable.com)
28
+ 2. Go to **Apps → API access → Access tokens → + Add new**
29
+ 3. Copy your token
30
+
31
+ ```ts
32
+ import { HospitableClient } from 'hospitable'
33
+
34
+ const client = new HospitableClient({ token: 'your_pat_token' })
35
+
36
+ // Or set HOSPITABLE_PAT env var and call with no args:
37
+ // const client = new HospitableClient()
38
+
39
+ const properties = await client.properties.list()
40
+ console.log(`Found ${properties.data.length} properties`)
41
+ ```
42
+
43
+ ### OAuth2
44
+
45
+ ```ts
46
+ // Client credentials (machine-to-machine)
47
+ const client = new HospitableClient({
48
+ clientId: 'your_client_id',
49
+ clientSecret: 'your_client_secret',
50
+ })
51
+
52
+ // With refresh token (long-lived sessions)
53
+ const client = new HospitableClient({
54
+ token: 'access_token',
55
+ refreshToken: 'refresh_token',
56
+ clientId: 'your_client_id',
57
+ clientSecret: 'your_client_secret',
58
+ })
59
+ // Token fetched and refreshed automatically; 401s trigger silent re-auth + retry
60
+ ```
61
+
62
+ ## Usage
63
+
64
+ ### Properties
65
+
66
+ ```ts
67
+ // List all properties
68
+ const { data } = await client.properties.list()
69
+
70
+ // Get a single property
71
+ const property = await client.properties.get('property-uuid')
72
+
73
+ // Iterate all (auto-pagination)
74
+ for await (const prop of client.properties.iter()) {
75
+ console.log(prop.name)
76
+ }
77
+
78
+ // Update calendar pricing
79
+ await client.properties.updateCalendar('property-uuid', [
80
+ { date: '2026-06-01', price: { amount: 15000 }, available: true, minStay: 2 },
81
+ ])
82
+ ```
83
+
84
+ ### Reservations
85
+
86
+ ```ts
87
+ // Upcoming confirmed reservations
88
+ const upcoming = await client.reservations.getUpcoming(['property-uuid'])
89
+
90
+ // List with filters
91
+ import { ReservationFilter } from 'hospitable'
92
+
93
+ const filter = new ReservationFilter()
94
+ .checkinAfter('2026-01-01')
95
+ .checkinBefore('2026-12-31')
96
+ .status('confirmed')
97
+ .include('guest', 'properties')
98
+ .perPage(50)
99
+
100
+ const results = await client.reservations.list(filter.toParams())
101
+
102
+ // Stream all (memory-efficient)
103
+ for await (const reservation of client.reservations.iter({ startDate: '2026-01-01' })) {
104
+ console.log(reservation.id, reservation.status)
105
+ }
106
+ ```
107
+
108
+ ### Messages
109
+
110
+ ```ts
111
+ // Send a message
112
+ await client.messages.send('reservation-uuid', 'Looking forward to hosting you!')
113
+
114
+ // List thread
115
+ const thread = await client.messages.list('reservation-uuid')
116
+
117
+ // List and send message templates
118
+ const templates = await client.messages.listTemplates()
119
+ await client.messages.sendTemplate('reservation-uuid', templates[0].id, { name: 'Alice' })
120
+ ```
121
+
122
+ ### Calendar
123
+
124
+ ```ts
125
+ // Get availability for a date range
126
+ const days = await client.calendar.get('property-uuid', '2026-07-01', '2026-07-31')
127
+
128
+ // Update pricing / availability
129
+ await client.calendar.update('property-uuid', [
130
+ { date: '2026-07-15', price: { amount: 20000 }, available: false },
131
+ ])
132
+
133
+ // Block dates (owner stays, maintenance, etc.)
134
+ await client.calendar.block('property-uuid', '2026-07-01', '2026-07-07', 'Owner stay')
135
+
136
+ // Unblock
137
+ await client.calendar.unblock('property-uuid', '2026-07-01', '2026-07-07')
138
+ ```
139
+
140
+ ### Reviews
141
+
142
+ ```ts
143
+ // List all reviews
144
+ const { data } = await client.reviews.list()
145
+
146
+ // Filter to unresponded only
147
+ for await (const review of client.reviews.iter({ responded: false })) {
148
+ await client.reviews.respond(review.id, 'Thank you for your kind words!')
149
+ }
150
+ ```
151
+
152
+ ## Error Handling
153
+
154
+ ```ts
155
+ import {
156
+ HospitableClient,
157
+ HospitableError,
158
+ RateLimitError,
159
+ AuthenticationError,
160
+ NotFoundError,
161
+ ForbiddenError,
162
+ ValidationError,
163
+ ServerError,
164
+ } from 'hospitable'
165
+
166
+ try {
167
+ const property = await client.properties.get('uuid')
168
+ } catch (err) {
169
+ if (err instanceof RateLimitError) {
170
+ console.log(`Rate limited. Retry after ${err.retryAfter}s`)
171
+ } else if (err instanceof AuthenticationError) {
172
+ console.log('Check your token')
173
+ } else if (err instanceof NotFoundError) {
174
+ console.log('Property not found')
175
+ } else if (err instanceof ForbiddenError) {
176
+ console.log('Insufficient permissions')
177
+ } else if (err instanceof ValidationError) {
178
+ console.log('Invalid request:', err.message)
179
+ } else if (err instanceof ServerError) {
180
+ console.log(`Server error after ${err.attempts} attempt(s)`)
181
+ } else if (err instanceof HospitableError) {
182
+ console.log(`API error ${err.statusCode}: ${err.message}`)
183
+ }
184
+ }
185
+ ```
186
+
187
+ ## Rate Limiting & Retries
188
+
189
+ The SDK automatically retries `429` and `5xx` errors with jittered exponential backoff (up to 4 attempts, max 60s delay). `401` responses trigger a silent token refresh and single retry when OAuth is configured.
190
+
191
+ ```ts
192
+ const client = new HospitableClient({
193
+ token: 'your_token',
194
+ retry: {
195
+ maxAttempts: 4,
196
+ baseDelay: 1000,
197
+ maxDelay: 60_000,
198
+ onRateLimit: ({ retryAfter, endpoint, attempt }) => {
199
+ console.warn(`Rate limited on ${endpoint}, attempt ${attempt}, retrying in ${retryAfter}s`)
200
+ },
201
+ },
202
+ })
203
+ ```
204
+
205
+ ## Debug Logging
206
+
207
+ ```ts
208
+ const client = new HospitableClient({ token: 'your_token', debug: true })
209
+ // Logs every request URL and response body with PII fields masked
210
+ ```
211
+
212
+ ## License
213
+
214
+ MIT