@skilder-ai/smoobu 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/LICENSE +21 -0
- package/README.md +57 -2
- package/dist/index.d.ts +450 -0
- package/dist/index.js +460 -0
- package/dist/index.js.map +1 -0
- package/package.json +45 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Skilder
|
|
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
|
@@ -1,3 +1,58 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @skilder-ai/smoobu
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Typed TypeScript client for the [Smoobu API](https://docs.smoobu.com/).
|
|
4
|
+
|
|
5
|
+
- **HMAC request signing** (`X-API-Key`, `X-Timestamp`, `X-Nonce`, `X-Signature`), with a fresh
|
|
6
|
+
nonce on every retry.
|
|
7
|
+
- **Validated responses** (zod). Smoobu's documentation and its real payloads differ, and the
|
|
8
|
+
schemas accept the real ones.
|
|
9
|
+
- **Clean domain model**: `Message`, `ConversationSummary`, and one page envelope everywhere
|
|
10
|
+
(`items/page/pageSize/pageCount/total`).
|
|
11
|
+
- **Robust transport**: timeouts, and retries on 429/5xx/network errors for GET requests only.
|
|
12
|
+
Rate-limit waits follow Smoobu's reset time.
|
|
13
|
+
- **Typed errors**: `SmoobuApiError` carries `status`, `code`
|
|
14
|
+
(`unauthorized | forbidden | not_found | validation | rate_limited | upstream | network`) and
|
|
15
|
+
`retryable`.
|
|
16
|
+
|
|
17
|
+
Requires Node ≥ 22 and `zod` 4 (peer dependency).
|
|
18
|
+
|
|
19
|
+
```sh
|
|
20
|
+
npm install @skilder-ai/smoobu zod
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
```ts
|
|
24
|
+
import { Smoobu, SmoobuApiError } from '@skilder-ai/smoobu';
|
|
25
|
+
|
|
26
|
+
const smoobu = new Smoobu({
|
|
27
|
+
apiKey: process.env.SMOOBU_API_KEY!,
|
|
28
|
+
apiSecret: process.env.SMOOBU_API_SECRET!,
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
const account = await smoobu.getAccount();
|
|
32
|
+
const conversations = await smoobu.messages.listConversations({ pageSize: 20 });
|
|
33
|
+
const thread = await smoobu.messages.list(123456789);
|
|
34
|
+
await smoobu.messages.send({ reservationId: 123456789, body: 'Welcome!', audience: 'guest' });
|
|
35
|
+
|
|
36
|
+
try {
|
|
37
|
+
await smoobu.messages.list(1);
|
|
38
|
+
} catch (err) {
|
|
39
|
+
if (err instanceof SmoobuApiError && err.code === 'not_found') {
|
|
40
|
+
/* … */
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
For endpoints not wrapped yet, use the low-level client, `smoobu.client`. It has one method per
|
|
46
|
+
endpoint and returns raw `wire` types.
|
|
47
|
+
|
|
48
|
+
## Smoobu quirks handled
|
|
49
|
+
|
|
50
|
+
- Messages use `htmlMessage`, although the docs' example says `messageHtml`. Both are accepted.
|
|
51
|
+
- Messages carry an undocumented `createdAt` (`YYYY-MM-DD HH:MM:SS`, timezone not documented). It
|
|
52
|
+
is exposed as an offset-less ISO local date-time.
|
|
53
|
+
- Threads can have `booking.id` and `apartment.id` set to `null` (inquiries without a booking).
|
|
54
|
+
- Pagination parameters differ per endpoint (`page` vs `page_number`, `page_size` vs `pageSize`).
|
|
55
|
+
This package normalises them.
|
|
56
|
+
- Without the key's **"Guest Data (PII)"** permission, guest names and message bodies come back as
|
|
57
|
+
empty strings.
|
|
58
|
+
- Sending returns no message id.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,450 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Raw Smoobu wire formats. These mirror Smoobu's JSON exactly — including its inconsistent
|
|
5
|
+
* casing — and are deliberately lenient (loose objects, optional fields): the docs are known to
|
|
6
|
+
* disagree with real payloads. Exported as `wire` for advanced use; prefer the domain types
|
|
7
|
+
* (types.ts) produced by mappers.ts.
|
|
8
|
+
*/
|
|
9
|
+
declare const smoobuErrorSchema: z.ZodObject<{
|
|
10
|
+
status: z.ZodOptional<z.ZodNumber>;
|
|
11
|
+
title: z.ZodOptional<z.ZodString>;
|
|
12
|
+
detail: z.ZodOptional<z.ZodString>;
|
|
13
|
+
validation_messages: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
14
|
+
}, z.core.$loose>;
|
|
15
|
+
type SmoobuErrorBody = z.infer<typeof smoobuErrorSchema>;
|
|
16
|
+
declare const smoobuUserSchema: z.ZodObject<{
|
|
17
|
+
id: z.ZodNumber;
|
|
18
|
+
firstName: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
19
|
+
lastName: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
20
|
+
email: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
21
|
+
}, z.core.$loose>;
|
|
22
|
+
type SmoobuUser = z.infer<typeof smoobuUserSchema>;
|
|
23
|
+
declare const smoobuMessageSchema: z.ZodObject<{
|
|
24
|
+
id: z.ZodNumber;
|
|
25
|
+
subject: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
26
|
+
message: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
27
|
+
messageHtml: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
28
|
+
htmlMessage: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
29
|
+
type: z.ZodNumber;
|
|
30
|
+
createdAt: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
31
|
+
}, z.core.$loose>;
|
|
32
|
+
type SmoobuMessage = z.infer<typeof smoobuMessageSchema>;
|
|
33
|
+
declare const smoobuMessagesPageSchema: z.ZodObject<{
|
|
34
|
+
page_count: z.ZodNumber;
|
|
35
|
+
page_size: z.ZodNumber;
|
|
36
|
+
total_items: z.ZodNumber;
|
|
37
|
+
page: z.ZodNumber;
|
|
38
|
+
messages: z.ZodArray<z.ZodObject<{
|
|
39
|
+
id: z.ZodNumber;
|
|
40
|
+
subject: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
41
|
+
message: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
42
|
+
messageHtml: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
43
|
+
htmlMessage: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
44
|
+
type: z.ZodNumber;
|
|
45
|
+
createdAt: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
46
|
+
}, z.core.$loose>>;
|
|
47
|
+
}, z.core.$loose>;
|
|
48
|
+
type SmoobuMessagesPage = z.infer<typeof smoobuMessagesPageSchema>;
|
|
49
|
+
declare const smoobuThreadSchema: z.ZodObject<{
|
|
50
|
+
booking: z.ZodObject<{
|
|
51
|
+
id: z.ZodNullable<z.ZodNumber>;
|
|
52
|
+
guest_name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
53
|
+
}, z.core.$loose>;
|
|
54
|
+
apartment: z.ZodOptional<z.ZodNullable<z.ZodObject<{
|
|
55
|
+
id: z.ZodNullable<z.ZodNumber>;
|
|
56
|
+
name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
57
|
+
}, z.core.$loose>>>;
|
|
58
|
+
latest_message: z.ZodOptional<z.ZodNullable<z.ZodObject<{
|
|
59
|
+
id: z.ZodNumber;
|
|
60
|
+
subject: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
61
|
+
text_content: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
62
|
+
html_content: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
63
|
+
created_at: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
64
|
+
}, z.core.$loose>>>;
|
|
65
|
+
}, z.core.$loose>;
|
|
66
|
+
type SmoobuThread = z.infer<typeof smoobuThreadSchema>;
|
|
67
|
+
declare const smoobuThreadsPageSchema: z.ZodObject<{
|
|
68
|
+
page_number: z.ZodNumber;
|
|
69
|
+
page_size: z.ZodNumber;
|
|
70
|
+
page_count: z.ZodNumber;
|
|
71
|
+
total_threads: z.ZodNumber;
|
|
72
|
+
unread_messages: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
|
|
73
|
+
threads: z.ZodArray<z.ZodObject<{
|
|
74
|
+
booking: z.ZodObject<{
|
|
75
|
+
id: z.ZodNullable<z.ZodNumber>;
|
|
76
|
+
guest_name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
77
|
+
}, z.core.$loose>;
|
|
78
|
+
apartment: z.ZodOptional<z.ZodNullable<z.ZodObject<{
|
|
79
|
+
id: z.ZodNullable<z.ZodNumber>;
|
|
80
|
+
name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
81
|
+
}, z.core.$loose>>>;
|
|
82
|
+
latest_message: z.ZodOptional<z.ZodNullable<z.ZodObject<{
|
|
83
|
+
id: z.ZodNumber;
|
|
84
|
+
subject: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
85
|
+
text_content: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
86
|
+
html_content: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
87
|
+
created_at: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
88
|
+
}, z.core.$loose>>>;
|
|
89
|
+
}, z.core.$loose>>;
|
|
90
|
+
}, z.core.$loose>;
|
|
91
|
+
type SmoobuThreadsPage = z.infer<typeof smoobuThreadsPageSchema>;
|
|
92
|
+
interface SmoobuSendMessageBody {
|
|
93
|
+
subject?: string;
|
|
94
|
+
/** HTML or plain text. */
|
|
95
|
+
messageBody: string;
|
|
96
|
+
/** Host messages only: hidden from the guest when true. */
|
|
97
|
+
internal?: boolean;
|
|
98
|
+
}
|
|
99
|
+
/** Envelope of every webhook call. `data` depends on `action`. */
|
|
100
|
+
declare const smoobuWebhookSchema: z.ZodObject<{
|
|
101
|
+
action: z.ZodString;
|
|
102
|
+
user: z.ZodNumber;
|
|
103
|
+
data: z.ZodUnknown;
|
|
104
|
+
}, z.core.$loose>;
|
|
105
|
+
declare const smoobuNewMessageDataSchema: z.ZodObject<{
|
|
106
|
+
id: z.ZodNumber;
|
|
107
|
+
sender: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
108
|
+
booking: z.ZodObject<{
|
|
109
|
+
id: z.ZodNumber;
|
|
110
|
+
}, z.core.$loose>;
|
|
111
|
+
}, z.core.$loose>;
|
|
112
|
+
|
|
113
|
+
type wire_SmoobuErrorBody = SmoobuErrorBody;
|
|
114
|
+
type wire_SmoobuMessage = SmoobuMessage;
|
|
115
|
+
type wire_SmoobuMessagesPage = SmoobuMessagesPage;
|
|
116
|
+
type wire_SmoobuSendMessageBody = SmoobuSendMessageBody;
|
|
117
|
+
type wire_SmoobuThread = SmoobuThread;
|
|
118
|
+
type wire_SmoobuThreadsPage = SmoobuThreadsPage;
|
|
119
|
+
type wire_SmoobuUser = SmoobuUser;
|
|
120
|
+
declare const wire_smoobuErrorSchema: typeof smoobuErrorSchema;
|
|
121
|
+
declare const wire_smoobuMessageSchema: typeof smoobuMessageSchema;
|
|
122
|
+
declare const wire_smoobuMessagesPageSchema: typeof smoobuMessagesPageSchema;
|
|
123
|
+
declare const wire_smoobuNewMessageDataSchema: typeof smoobuNewMessageDataSchema;
|
|
124
|
+
declare const wire_smoobuThreadSchema: typeof smoobuThreadSchema;
|
|
125
|
+
declare const wire_smoobuThreadsPageSchema: typeof smoobuThreadsPageSchema;
|
|
126
|
+
declare const wire_smoobuUserSchema: typeof smoobuUserSchema;
|
|
127
|
+
declare const wire_smoobuWebhookSchema: typeof smoobuWebhookSchema;
|
|
128
|
+
declare namespace wire {
|
|
129
|
+
export { wire_smoobuErrorSchema as smoobuErrorSchema, wire_smoobuMessageSchema as smoobuMessageSchema, wire_smoobuMessagesPageSchema as smoobuMessagesPageSchema, wire_smoobuNewMessageDataSchema as smoobuNewMessageDataSchema, wire_smoobuThreadSchema as smoobuThreadSchema, wire_smoobuThreadsPageSchema as smoobuThreadsPageSchema, wire_smoobuUserSchema as smoobuUserSchema, wire_smoobuWebhookSchema as smoobuWebhookSchema };
|
|
130
|
+
export type { wire_SmoobuErrorBody as SmoobuErrorBody, wire_SmoobuMessage as SmoobuMessage, wire_SmoobuMessagesPage as SmoobuMessagesPage, wire_SmoobuSendMessageBody as SmoobuSendMessageBody, wire_SmoobuThread as SmoobuThread, wire_SmoobuThreadsPage as SmoobuThreadsPage, wire_SmoobuUser as SmoobuUser };
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
interface SmoobuClientOptions {
|
|
134
|
+
apiKey: string;
|
|
135
|
+
apiSecret: string;
|
|
136
|
+
baseUrl?: string;
|
|
137
|
+
/** Per-attempt timeout. */
|
|
138
|
+
timeoutMs?: number;
|
|
139
|
+
/** Extra attempts on 429 / 5xx / network errors (GET only: POSTs are not idempotent). */
|
|
140
|
+
maxRetries?: number;
|
|
141
|
+
/** Sent as User-Agent, e.g. `my-app/1.2.3`. */
|
|
142
|
+
userAgent?: string;
|
|
143
|
+
/** Injectable for tests. */
|
|
144
|
+
fetch?: typeof fetch;
|
|
145
|
+
sleep?: (ms: number) => Promise<void>;
|
|
146
|
+
}
|
|
147
|
+
type SmoobuErrorCode = 'unauthorized' | 'forbidden' | 'not_found' | 'validation' | 'rate_limited' | 'upstream' | 'network';
|
|
148
|
+
/** Any non-2xx answer (or unreachable API). `status` 0 = network/timeout. */
|
|
149
|
+
declare class SmoobuApiError extends Error {
|
|
150
|
+
readonly status: number;
|
|
151
|
+
readonly body?: SmoobuErrorBody | undefined;
|
|
152
|
+
readonly name = "SmoobuApiError";
|
|
153
|
+
readonly code: SmoobuErrorCode;
|
|
154
|
+
/** Worth retrying later (rate limit, 5xx, network). */
|
|
155
|
+
readonly retryable: boolean;
|
|
156
|
+
constructor(status: number, message: string, body?: SmoobuErrorBody | undefined, options?: ErrorOptions & {
|
|
157
|
+
retryAfterMs?: number;
|
|
158
|
+
});
|
|
159
|
+
/** For rate limits: how long until the window resets, when Smoobu says so. */
|
|
160
|
+
readonly retryAfterMs: number | undefined;
|
|
161
|
+
}
|
|
162
|
+
/** Smoobu answered 2xx but the payload did not match the expected shape. */
|
|
163
|
+
declare class SmoobuResponseShapeError extends Error {
|
|
164
|
+
readonly path: string;
|
|
165
|
+
readonly issues: z.core.$ZodIssue[];
|
|
166
|
+
readonly name = "SmoobuResponseShapeError";
|
|
167
|
+
constructor(path: string, issues: z.core.$ZodIssue[]);
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Low-level, typed Smoobu HTTP client. One method per endpoint, returns validated *wire* types.
|
|
171
|
+
* Knows nothing about the domain model (see `Smoobu` for that).
|
|
172
|
+
*/
|
|
173
|
+
declare class SmoobuClient {
|
|
174
|
+
private readonly opts;
|
|
175
|
+
private readonly baseUrl;
|
|
176
|
+
private readonly timeoutMs;
|
|
177
|
+
private readonly maxRetries;
|
|
178
|
+
private readonly fetchFn;
|
|
179
|
+
private readonly sleep;
|
|
180
|
+
constructor(opts: SmoobuClientOptions);
|
|
181
|
+
/** GET /api/me — the account the API key belongs to. Cheapest connectivity check. */
|
|
182
|
+
getMe(): Promise<{
|
|
183
|
+
[x: string]: unknown;
|
|
184
|
+
id: number;
|
|
185
|
+
firstName?: string | null | undefined;
|
|
186
|
+
lastName?: string | null | undefined;
|
|
187
|
+
email?: string | null | undefined;
|
|
188
|
+
}>;
|
|
189
|
+
/** GET /api/threads — conversation list with the latest message of each booking. */
|
|
190
|
+
listThreads(params?: {
|
|
191
|
+
page?: number;
|
|
192
|
+
pageSize?: number;
|
|
193
|
+
apartmentIds?: number[];
|
|
194
|
+
}): Promise<{
|
|
195
|
+
[x: string]: unknown;
|
|
196
|
+
page_number: number;
|
|
197
|
+
page_size: number;
|
|
198
|
+
page_count: number;
|
|
199
|
+
total_threads: number;
|
|
200
|
+
threads: {
|
|
201
|
+
[x: string]: unknown;
|
|
202
|
+
booking: {
|
|
203
|
+
[x: string]: unknown;
|
|
204
|
+
id: number | null;
|
|
205
|
+
guest_name?: string | null | undefined;
|
|
206
|
+
};
|
|
207
|
+
apartment?: {
|
|
208
|
+
[x: string]: unknown;
|
|
209
|
+
id: number | null;
|
|
210
|
+
name?: string | null | undefined;
|
|
211
|
+
} | null | undefined;
|
|
212
|
+
latest_message?: {
|
|
213
|
+
[x: string]: unknown;
|
|
214
|
+
id: number;
|
|
215
|
+
subject?: string | null | undefined;
|
|
216
|
+
text_content?: string | null | undefined;
|
|
217
|
+
html_content?: string | null | undefined;
|
|
218
|
+
created_at?: string | null | undefined;
|
|
219
|
+
} | null | undefined;
|
|
220
|
+
}[];
|
|
221
|
+
unread_messages?: number | null | undefined;
|
|
222
|
+
}>;
|
|
223
|
+
/** GET /api/reservations/{id}/messages */
|
|
224
|
+
listReservationMessages(reservationId: number, params?: {
|
|
225
|
+
page?: number;
|
|
226
|
+
onlyRelatedToGuest?: boolean;
|
|
227
|
+
}): Promise<{
|
|
228
|
+
[x: string]: unknown;
|
|
229
|
+
page_count: number;
|
|
230
|
+
page_size: number;
|
|
231
|
+
total_items: number;
|
|
232
|
+
page: number;
|
|
233
|
+
messages: {
|
|
234
|
+
[x: string]: unknown;
|
|
235
|
+
id: number;
|
|
236
|
+
type: number;
|
|
237
|
+
subject?: string | null | undefined;
|
|
238
|
+
message?: string | null | undefined;
|
|
239
|
+
messageHtml?: string | null | undefined;
|
|
240
|
+
htmlMessage?: string | null | undefined;
|
|
241
|
+
createdAt?: string | null | undefined;
|
|
242
|
+
}[];
|
|
243
|
+
}>;
|
|
244
|
+
/** POST /api/reservations/{id}/messages/send-message-to-guest (no message id is returned). */
|
|
245
|
+
sendMessageToGuest(reservationId: number, body: Omit<SmoobuSendMessageBody, 'internal'>): Promise<{
|
|
246
|
+
[x: string]: unknown;
|
|
247
|
+
status?: number | undefined;
|
|
248
|
+
title?: string | undefined;
|
|
249
|
+
detail?: string | undefined;
|
|
250
|
+
validation_messages?: Record<string, unknown> | undefined;
|
|
251
|
+
}>;
|
|
252
|
+
/** POST /api/reservations/{id}/messages/send-message-to-host (`internal` hides it from the guest). */
|
|
253
|
+
sendMessageToHost(reservationId: number, body: SmoobuSendMessageBody): Promise<{
|
|
254
|
+
[x: string]: unknown;
|
|
255
|
+
status?: number | undefined;
|
|
256
|
+
title?: string | undefined;
|
|
257
|
+
detail?: string | undefined;
|
|
258
|
+
validation_messages?: Record<string, unknown> | undefined;
|
|
259
|
+
}>;
|
|
260
|
+
private request;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
/**
|
|
264
|
+
* Clean, provider-neutral messaging model. Smoobu's wire format (see wire.ts) is mapped to these
|
|
265
|
+
* shapes by mappers.ts so consumers never deal with its inconsistent casing, integer enums,
|
|
266
|
+
* naive dates or empty strings.
|
|
267
|
+
*
|
|
268
|
+
* Timestamps are ISO 8601 *local* date-times without offset (`2026-11-17T10:20:27`): Smoobu
|
|
269
|
+
* returns naive "YYYY-MM-DD HH:MM:SS" values and does not document their timezone.
|
|
270
|
+
*/
|
|
271
|
+
/** inbound = written by the guest, outbound = written by the host (or an automation). */
|
|
272
|
+
declare const messageDirectionSchema: z.ZodEnum<{
|
|
273
|
+
inbound: "inbound";
|
|
274
|
+
outbound: "outbound";
|
|
275
|
+
}>;
|
|
276
|
+
type MessageDirection = z.infer<typeof messageDirectionSchema>;
|
|
277
|
+
declare const messageSchema: z.ZodObject<{
|
|
278
|
+
id: z.ZodNumber;
|
|
279
|
+
reservationId: z.ZodNumber;
|
|
280
|
+
direction: z.ZodEnum<{
|
|
281
|
+
inbound: "inbound";
|
|
282
|
+
outbound: "outbound";
|
|
283
|
+
}>;
|
|
284
|
+
subject: z.ZodNullable<z.ZodString>;
|
|
285
|
+
text: z.ZodString;
|
|
286
|
+
html: z.ZodNullable<z.ZodString>;
|
|
287
|
+
sentAt: z.ZodNullable<z.ZodISODateTime>;
|
|
288
|
+
}, z.core.$strip>;
|
|
289
|
+
type Message = z.infer<typeof messageSchema>;
|
|
290
|
+
/** One conversation per reservation (or per inquiry, which has no reservation yet). */
|
|
291
|
+
declare const conversationSummarySchema: z.ZodObject<{
|
|
292
|
+
reservationId: z.ZodNullable<z.ZodNumber>;
|
|
293
|
+
guestName: z.ZodNullable<z.ZodString>;
|
|
294
|
+
property: z.ZodNullable<z.ZodObject<{
|
|
295
|
+
id: z.ZodNullable<z.ZodNumber>;
|
|
296
|
+
name: z.ZodNullable<z.ZodString>;
|
|
297
|
+
}, z.core.$strip>>;
|
|
298
|
+
lastMessage: z.ZodNullable<z.ZodObject<{
|
|
299
|
+
id: z.ZodNumber;
|
|
300
|
+
subject: z.ZodNullable<z.ZodString>;
|
|
301
|
+
preview: z.ZodString;
|
|
302
|
+
sentAt: z.ZodNullable<z.ZodISODateTime>;
|
|
303
|
+
}, z.core.$strip>>;
|
|
304
|
+
}, z.core.$strip>;
|
|
305
|
+
type ConversationSummary = z.infer<typeof conversationSummarySchema>;
|
|
306
|
+
/** Uniform page envelope (Smoobu uses three different pagination vocabularies). */
|
|
307
|
+
declare const pageSchema: <T extends z.ZodType>(item: T) => z.ZodObject<{
|
|
308
|
+
items: z.ZodArray<T>;
|
|
309
|
+
page: z.ZodNumber;
|
|
310
|
+
pageSize: z.ZodNumber;
|
|
311
|
+
pageCount: z.ZodNumber;
|
|
312
|
+
total: z.ZodNumber;
|
|
313
|
+
}, z.core.$strip>;
|
|
314
|
+
type Page<T> = {
|
|
315
|
+
items: T[];
|
|
316
|
+
page: number;
|
|
317
|
+
pageSize: number;
|
|
318
|
+
pageCount: number;
|
|
319
|
+
total: number;
|
|
320
|
+
};
|
|
321
|
+
declare const conversationPageSchema: z.ZodObject<{
|
|
322
|
+
items: z.ZodArray<z.ZodObject<{
|
|
323
|
+
reservationId: z.ZodNullable<z.ZodNumber>;
|
|
324
|
+
guestName: z.ZodNullable<z.ZodString>;
|
|
325
|
+
property: z.ZodNullable<z.ZodObject<{
|
|
326
|
+
id: z.ZodNullable<z.ZodNumber>;
|
|
327
|
+
name: z.ZodNullable<z.ZodString>;
|
|
328
|
+
}, z.core.$strip>>;
|
|
329
|
+
lastMessage: z.ZodNullable<z.ZodObject<{
|
|
330
|
+
id: z.ZodNumber;
|
|
331
|
+
subject: z.ZodNullable<z.ZodString>;
|
|
332
|
+
preview: z.ZodString;
|
|
333
|
+
sentAt: z.ZodNullable<z.ZodISODateTime>;
|
|
334
|
+
}, z.core.$strip>>;
|
|
335
|
+
}, z.core.$strip>>;
|
|
336
|
+
page: z.ZodNumber;
|
|
337
|
+
pageSize: z.ZodNumber;
|
|
338
|
+
pageCount: z.ZodNumber;
|
|
339
|
+
total: z.ZodNumber;
|
|
340
|
+
unreadMessages: z.ZodNullable<z.ZodNumber>;
|
|
341
|
+
}, z.core.$strip>;
|
|
342
|
+
type ConversationPage = z.infer<typeof conversationPageSchema>;
|
|
343
|
+
declare const messagePageSchema: z.ZodObject<{
|
|
344
|
+
items: z.ZodArray<z.ZodObject<{
|
|
345
|
+
id: z.ZodNumber;
|
|
346
|
+
reservationId: z.ZodNumber;
|
|
347
|
+
direction: z.ZodEnum<{
|
|
348
|
+
inbound: "inbound";
|
|
349
|
+
outbound: "outbound";
|
|
350
|
+
}>;
|
|
351
|
+
subject: z.ZodNullable<z.ZodString>;
|
|
352
|
+
text: z.ZodString;
|
|
353
|
+
html: z.ZodNullable<z.ZodString>;
|
|
354
|
+
sentAt: z.ZodNullable<z.ZodISODateTime>;
|
|
355
|
+
}, z.core.$strip>>;
|
|
356
|
+
page: z.ZodNumber;
|
|
357
|
+
pageSize: z.ZodNumber;
|
|
358
|
+
pageCount: z.ZodNumber;
|
|
359
|
+
total: z.ZodNumber;
|
|
360
|
+
}, z.core.$strip>;
|
|
361
|
+
type MessagePage = z.infer<typeof messagePageSchema>;
|
|
362
|
+
/** guest = visible to the guest; internal = host-only note on the reservation. */
|
|
363
|
+
declare const messageAudienceSchema: z.ZodEnum<{
|
|
364
|
+
guest: "guest";
|
|
365
|
+
internal: "internal";
|
|
366
|
+
}>;
|
|
367
|
+
type MessageAudience = z.infer<typeof messageAudienceSchema>;
|
|
368
|
+
interface SendMessageInput {
|
|
369
|
+
reservationId: number;
|
|
370
|
+
/** Plain text or HTML. */
|
|
371
|
+
body: string;
|
|
372
|
+
subject?: string;
|
|
373
|
+
/** Default: guest. */
|
|
374
|
+
audience?: MessageAudience;
|
|
375
|
+
}
|
|
376
|
+
interface Account {
|
|
377
|
+
id: number;
|
|
378
|
+
firstName: string | null;
|
|
379
|
+
lastName: string | null;
|
|
380
|
+
email: string | null;
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
/**
|
|
384
|
+
* High-level Smoobu API: speaks the clean domain model (types.ts). Use `.client` for raw,
|
|
385
|
+
* endpoint-level access to anything not covered here yet.
|
|
386
|
+
*/
|
|
387
|
+
declare class Smoobu {
|
|
388
|
+
readonly client: SmoobuClient;
|
|
389
|
+
constructor(options: SmoobuClientOptions | SmoobuClient);
|
|
390
|
+
/** The account the API key belongs to (GET /api/me). The cheapest credentials check. */
|
|
391
|
+
getAccount(): Promise<Account>;
|
|
392
|
+
readonly messages: {
|
|
393
|
+
/** Conversations, most recent first, with the latest message of each (GET /api/threads). */
|
|
394
|
+
listConversations: (params?: {
|
|
395
|
+
page?: number;
|
|
396
|
+
pageSize?: number;
|
|
397
|
+
propertyIds?: number[];
|
|
398
|
+
}) => Promise<ConversationPage>;
|
|
399
|
+
/** Messages of one reservation, oldest first. Smoobu fixes the page size (25). */
|
|
400
|
+
list: (reservationId: number, params?: {
|
|
401
|
+
page?: number;
|
|
402
|
+
onlyRelatedToGuest?: boolean;
|
|
403
|
+
}) => Promise<MessagePage>;
|
|
404
|
+
/**
|
|
405
|
+
* Sends a message to the guest, or an internal host-only note (audience: 'internal').
|
|
406
|
+
* Smoobu returns no message id: list the reservation's messages to see it.
|
|
407
|
+
*/
|
|
408
|
+
send: ({ reservationId, body, subject, audience }: SendMessageInput) => Promise<{
|
|
409
|
+
accepted: true;
|
|
410
|
+
}>;
|
|
411
|
+
};
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
/**
|
|
415
|
+
* Smoobu HMAC request signing (https://docs.smoobu.com/ → Authentication).
|
|
416
|
+
*
|
|
417
|
+
* canonical = METHOD \n PATH \n QUERY \n TIMESTAMP \n NONCE \n sha256hex(BODY) \n API_KEY
|
|
418
|
+
* X-Signature = base64(hmacSha256(secret, canonical))
|
|
419
|
+
*
|
|
420
|
+
* QUERY is sorted and RFC 3986 encoded (spaces → %20, brackets → %5B%5D); it is an empty line
|
|
421
|
+
* when there are no parameters. The exact same query string must be sent on the wire.
|
|
422
|
+
*/
|
|
423
|
+
type QueryValue = string | number | boolean | undefined | null | readonly (string | number)[];
|
|
424
|
+
type Query = Record<string, QueryValue>;
|
|
425
|
+
/** Builds the sorted, RFC 3986-encoded query string (without the leading `?`). */
|
|
426
|
+
declare function canonicalQuery(query?: Query): string;
|
|
427
|
+
interface SignInput {
|
|
428
|
+
method: string;
|
|
429
|
+
path: string;
|
|
430
|
+
/** Already canonicalised query string (see canonicalQuery). */
|
|
431
|
+
query: string;
|
|
432
|
+
/** Raw request body exactly as sent ('' for none). */
|
|
433
|
+
body: string;
|
|
434
|
+
apiKey: string;
|
|
435
|
+
apiSecret: string;
|
|
436
|
+
/** Injectable for tests. */
|
|
437
|
+
timestamp?: string;
|
|
438
|
+
nonce?: string;
|
|
439
|
+
}
|
|
440
|
+
declare function signRequest(input: SignInput): Record<string, string>;
|
|
441
|
+
|
|
442
|
+
declare function htmlToText(html: string): string;
|
|
443
|
+
|
|
444
|
+
/** "YYYY-MM-DD HH:MM:SS" → "YYYY-MM-DDTHH:MM:SS"; anything unexpected → null. */
|
|
445
|
+
declare function toLocalDateTime(value: string | null | undefined): string | null;
|
|
446
|
+
declare function toMessage(reservationId: number, m: SmoobuMessage): Message;
|
|
447
|
+
declare function toConversationSummary(t: SmoobuThread): ConversationSummary;
|
|
448
|
+
|
|
449
|
+
export { Smoobu, SmoobuApiError, SmoobuClient, SmoobuResponseShapeError, canonicalQuery, conversationPageSchema, conversationSummarySchema, htmlToText, messageAudienceSchema, messageDirectionSchema, messagePageSchema, messageSchema, pageSchema, signRequest, toConversationSummary, toLocalDateTime, toMessage, wire };
|
|
450
|
+
export type { Account, ConversationPage, ConversationSummary, Message, MessageAudience, MessageDirection, MessagePage, Page, Query, QueryValue, SendMessageInput, SignInput, SmoobuClientOptions, SmoobuErrorCode };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,460 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __export = (target, all) => {
|
|
3
|
+
for (var name in all)
|
|
4
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
// src/auth.ts
|
|
8
|
+
import { createHash, createHmac, randomUUID } from "crypto";
|
|
9
|
+
var rfc3986 = (value) => encodeURIComponent(value).replace(
|
|
10
|
+
/[!'()*]/g,
|
|
11
|
+
(c) => `%${c.charCodeAt(0).toString(16).toUpperCase()}`
|
|
12
|
+
);
|
|
13
|
+
function canonicalQuery(query = {}) {
|
|
14
|
+
const pairs = [];
|
|
15
|
+
for (const [key, value] of Object.entries(query)) {
|
|
16
|
+
if (value === void 0 || value === null) continue;
|
|
17
|
+
if (Array.isArray(value)) {
|
|
18
|
+
for (const item of value) pairs.push([`${key}[]`, String(item)]);
|
|
19
|
+
} else {
|
|
20
|
+
pairs.push([key, String(value)]);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return pairs.map(([k, v]) => [rfc3986(k), rfc3986(v)]).sort(([ak, av], [bk, bv]) => ak === bk ? av < bv ? -1 : 1 : ak < bk ? -1 : 1).map(([k, v]) => `${k}=${v}`).join("&");
|
|
24
|
+
}
|
|
25
|
+
function signRequest(input) {
|
|
26
|
+
const timestamp = input.timestamp ?? (/* @__PURE__ */ new Date()).toISOString().replace(/\.\d{3}Z$/, "Z");
|
|
27
|
+
const nonce = input.nonce ?? randomUUID();
|
|
28
|
+
const bodyHash = createHash("sha256").update(input.body).digest("hex");
|
|
29
|
+
const canonical = [
|
|
30
|
+
input.method.toUpperCase(),
|
|
31
|
+
input.path,
|
|
32
|
+
input.query,
|
|
33
|
+
timestamp,
|
|
34
|
+
nonce,
|
|
35
|
+
bodyHash,
|
|
36
|
+
input.apiKey
|
|
37
|
+
].join("\n");
|
|
38
|
+
const signature = createHmac("sha256", input.apiSecret).update(canonical).digest("base64");
|
|
39
|
+
return {
|
|
40
|
+
"X-API-Key": input.apiKey,
|
|
41
|
+
"X-Timestamp": timestamp,
|
|
42
|
+
"X-Nonce": nonce,
|
|
43
|
+
"X-Signature": signature
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// src/wire.ts
|
|
48
|
+
var wire_exports = {};
|
|
49
|
+
__export(wire_exports, {
|
|
50
|
+
smoobuErrorSchema: () => smoobuErrorSchema,
|
|
51
|
+
smoobuMessageSchema: () => smoobuMessageSchema,
|
|
52
|
+
smoobuMessagesPageSchema: () => smoobuMessagesPageSchema,
|
|
53
|
+
smoobuNewMessageDataSchema: () => smoobuNewMessageDataSchema,
|
|
54
|
+
smoobuThreadSchema: () => smoobuThreadSchema,
|
|
55
|
+
smoobuThreadsPageSchema: () => smoobuThreadsPageSchema,
|
|
56
|
+
smoobuUserSchema: () => smoobuUserSchema,
|
|
57
|
+
smoobuWebhookSchema: () => smoobuWebhookSchema
|
|
58
|
+
});
|
|
59
|
+
import { z } from "zod";
|
|
60
|
+
var smoobuErrorSchema = z.looseObject({
|
|
61
|
+
status: z.number().optional(),
|
|
62
|
+
title: z.string().optional(),
|
|
63
|
+
detail: z.string().optional(),
|
|
64
|
+
validation_messages: z.record(z.string(), z.unknown()).optional()
|
|
65
|
+
});
|
|
66
|
+
var smoobuUserSchema = z.looseObject({
|
|
67
|
+
id: z.number(),
|
|
68
|
+
firstName: z.string().nullish(),
|
|
69
|
+
lastName: z.string().nullish(),
|
|
70
|
+
email: z.string().nullish()
|
|
71
|
+
});
|
|
72
|
+
var smoobuMessageSchema = z.looseObject({
|
|
73
|
+
id: z.number(),
|
|
74
|
+
subject: z.string().nullish(),
|
|
75
|
+
message: z.string().nullish(),
|
|
76
|
+
// The docs' example says `messageHtml`, the field table says `htmlMessage`: accept both.
|
|
77
|
+
messageHtml: z.string().nullish(),
|
|
78
|
+
htmlMessage: z.string().nullish(),
|
|
79
|
+
/** 1 = inbox (received from the guest), 2 = outbox (sent by the host). */
|
|
80
|
+
type: z.number(),
|
|
81
|
+
/** "YYYY-MM-DD HH:MM:SS" (observed; undocumented), timezone not stated. */
|
|
82
|
+
createdAt: z.string().nullish()
|
|
83
|
+
});
|
|
84
|
+
var smoobuMessagesPageSchema = z.looseObject({
|
|
85
|
+
page_count: z.number(),
|
|
86
|
+
page_size: z.number(),
|
|
87
|
+
total_items: z.number(),
|
|
88
|
+
page: z.number(),
|
|
89
|
+
messages: z.array(smoobuMessageSchema)
|
|
90
|
+
});
|
|
91
|
+
var smoobuThreadSchema = z.looseObject({
|
|
92
|
+
// Observed in production: some threads (inquiries?) have `booking.id` and `apartment.id` = null.
|
|
93
|
+
booking: z.looseObject({ id: z.number().nullable(), guest_name: z.string().nullish() }),
|
|
94
|
+
apartment: z.looseObject({ id: z.number().nullable(), name: z.string().nullish() }).nullish(),
|
|
95
|
+
latest_message: z.looseObject({
|
|
96
|
+
id: z.number(),
|
|
97
|
+
subject: z.string().nullish(),
|
|
98
|
+
text_content: z.string().nullish(),
|
|
99
|
+
html_content: z.string().nullish(),
|
|
100
|
+
/** "YYYY-MM-DD HH:MM:SS", timezone not documented. */
|
|
101
|
+
created_at: z.string().nullish()
|
|
102
|
+
}).nullish()
|
|
103
|
+
});
|
|
104
|
+
var smoobuThreadsPageSchema = z.looseObject({
|
|
105
|
+
page_number: z.number(),
|
|
106
|
+
page_size: z.number(),
|
|
107
|
+
page_count: z.number(),
|
|
108
|
+
total_threads: z.number(),
|
|
109
|
+
unread_messages: z.number().nullish(),
|
|
110
|
+
threads: z.array(smoobuThreadSchema)
|
|
111
|
+
});
|
|
112
|
+
var smoobuWebhookSchema = z.looseObject({
|
|
113
|
+
action: z.string(),
|
|
114
|
+
user: z.number(),
|
|
115
|
+
data: z.unknown()
|
|
116
|
+
});
|
|
117
|
+
var smoobuNewMessageDataSchema = z.looseObject({
|
|
118
|
+
id: z.number(),
|
|
119
|
+
sender: z.string().nullish(),
|
|
120
|
+
booking: z.looseObject({ id: z.number() })
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
// src/client.ts
|
|
124
|
+
function errorCode(status) {
|
|
125
|
+
if (status === 0) return "network";
|
|
126
|
+
if (status === 401) return "unauthorized";
|
|
127
|
+
if (status === 403) return "forbidden";
|
|
128
|
+
if (status === 404) return "not_found";
|
|
129
|
+
if (status === 400 || status === 409 || status === 422) return "validation";
|
|
130
|
+
if (status === 429) return "rate_limited";
|
|
131
|
+
return "upstream";
|
|
132
|
+
}
|
|
133
|
+
var SmoobuApiError = class extends Error {
|
|
134
|
+
constructor(status, message, body, options) {
|
|
135
|
+
super(message, options);
|
|
136
|
+
this.status = status;
|
|
137
|
+
this.body = body;
|
|
138
|
+
this.code = errorCode(status);
|
|
139
|
+
this.retryable = status === 0 || status === 429 || status >= 500;
|
|
140
|
+
this.retryAfterMs = options?.retryAfterMs;
|
|
141
|
+
}
|
|
142
|
+
status;
|
|
143
|
+
body;
|
|
144
|
+
name = "SmoobuApiError";
|
|
145
|
+
code;
|
|
146
|
+
/** Worth retrying later (rate limit, 5xx, network). */
|
|
147
|
+
retryable;
|
|
148
|
+
/** For rate limits: how long until the window resets, when Smoobu says so. */
|
|
149
|
+
retryAfterMs;
|
|
150
|
+
};
|
|
151
|
+
var SmoobuResponseShapeError = class extends Error {
|
|
152
|
+
constructor(path, issues) {
|
|
153
|
+
super(`Unexpected Smoobu response for ${path}`);
|
|
154
|
+
this.path = path;
|
|
155
|
+
this.issues = issues;
|
|
156
|
+
}
|
|
157
|
+
path;
|
|
158
|
+
issues;
|
|
159
|
+
name = "SmoobuResponseShapeError";
|
|
160
|
+
};
|
|
161
|
+
var SmoobuClient = class {
|
|
162
|
+
constructor(opts) {
|
|
163
|
+
this.opts = opts;
|
|
164
|
+
this.baseUrl = (opts.baseUrl ?? "https://login.smoobu.com").replace(/\/+$/, "");
|
|
165
|
+
this.timeoutMs = opts.timeoutMs ?? 15e3;
|
|
166
|
+
this.maxRetries = opts.maxRetries ?? 2;
|
|
167
|
+
this.fetchFn = opts.fetch ?? fetch;
|
|
168
|
+
this.sleep = opts.sleep ?? ((ms) => new Promise((r) => setTimeout(r, ms)));
|
|
169
|
+
}
|
|
170
|
+
opts;
|
|
171
|
+
baseUrl;
|
|
172
|
+
timeoutMs;
|
|
173
|
+
maxRetries;
|
|
174
|
+
fetchFn;
|
|
175
|
+
sleep;
|
|
176
|
+
// --- Endpoints -------------------------------------------------------------------------------
|
|
177
|
+
/** GET /api/me — the account the API key belongs to. Cheapest connectivity check. */
|
|
178
|
+
getMe() {
|
|
179
|
+
return this.request("GET", "/api/me", { schema: smoobuUserSchema });
|
|
180
|
+
}
|
|
181
|
+
/** GET /api/threads — conversation list with the latest message of each booking. */
|
|
182
|
+
listThreads(params = {}) {
|
|
183
|
+
return this.request("GET", "/api/threads", {
|
|
184
|
+
query: {
|
|
185
|
+
page_number: params.page,
|
|
186
|
+
page_size: params.pageSize,
|
|
187
|
+
apartments: params.apartmentIds
|
|
188
|
+
},
|
|
189
|
+
schema: smoobuThreadsPageSchema
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
/** GET /api/reservations/{id}/messages */
|
|
193
|
+
listReservationMessages(reservationId, params = {}) {
|
|
194
|
+
return this.request("GET", `/api/reservations/${reservationId}/messages`, {
|
|
195
|
+
query: { page: params.page, onlyRelatedToGuest: params.onlyRelatedToGuest },
|
|
196
|
+
schema: smoobuMessagesPageSchema
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
/** POST /api/reservations/{id}/messages/send-message-to-guest (no message id is returned). */
|
|
200
|
+
sendMessageToGuest(reservationId, body) {
|
|
201
|
+
return this.request(
|
|
202
|
+
"POST",
|
|
203
|
+
`/api/reservations/${reservationId}/messages/send-message-to-guest`,
|
|
204
|
+
{ body, schema: smoobuErrorSchema }
|
|
205
|
+
);
|
|
206
|
+
}
|
|
207
|
+
/** POST /api/reservations/{id}/messages/send-message-to-host (`internal` hides it from the guest). */
|
|
208
|
+
sendMessageToHost(reservationId, body) {
|
|
209
|
+
return this.request(
|
|
210
|
+
"POST",
|
|
211
|
+
`/api/reservations/${reservationId}/messages/send-message-to-host`,
|
|
212
|
+
{
|
|
213
|
+
body,
|
|
214
|
+
schema: smoobuErrorSchema
|
|
215
|
+
}
|
|
216
|
+
);
|
|
217
|
+
}
|
|
218
|
+
// --- Transport -------------------------------------------------------------------------------
|
|
219
|
+
async request(method, path, { query, body, schema }) {
|
|
220
|
+
const qs = canonicalQuery(query);
|
|
221
|
+
const rawBody = body === void 0 ? "" : JSON.stringify(body);
|
|
222
|
+
const url = `${this.baseUrl}${path}${qs ? `?${qs}` : ""}`;
|
|
223
|
+
const retries = method === "GET" ? this.maxRetries : 0;
|
|
224
|
+
for (let attempt = 0; ; attempt++) {
|
|
225
|
+
let res;
|
|
226
|
+
try {
|
|
227
|
+
res = await this.fetchFn(url, {
|
|
228
|
+
method,
|
|
229
|
+
headers: {
|
|
230
|
+
Accept: "application/json",
|
|
231
|
+
...this.opts.userAgent ? { "User-Agent": this.opts.userAgent } : {},
|
|
232
|
+
...rawBody ? { "Content-Type": "application/json" } : {},
|
|
233
|
+
...signRequest({
|
|
234
|
+
method,
|
|
235
|
+
path,
|
|
236
|
+
query: qs,
|
|
237
|
+
body: rawBody,
|
|
238
|
+
apiKey: this.opts.apiKey,
|
|
239
|
+
apiSecret: this.opts.apiSecret
|
|
240
|
+
})
|
|
241
|
+
},
|
|
242
|
+
body: rawBody || void 0,
|
|
243
|
+
signal: AbortSignal.timeout(this.timeoutMs)
|
|
244
|
+
});
|
|
245
|
+
} catch (err) {
|
|
246
|
+
if (attempt < retries) {
|
|
247
|
+
await this.sleep(backoff(attempt));
|
|
248
|
+
continue;
|
|
249
|
+
}
|
|
250
|
+
throw new SmoobuApiError(0, `Smoobu unreachable: ${err.message}`, void 0, {
|
|
251
|
+
cause: err
|
|
252
|
+
});
|
|
253
|
+
}
|
|
254
|
+
const json = res.status === 204 ? void 0 : await res.json().catch(() => void 0);
|
|
255
|
+
if (!res.ok) {
|
|
256
|
+
const retryable = res.status === 429 || res.status >= 500;
|
|
257
|
+
if (retryable && attempt < retries) {
|
|
258
|
+
await this.sleep(retryDelay(res, attempt));
|
|
259
|
+
continue;
|
|
260
|
+
}
|
|
261
|
+
const errBody = smoobuErrorSchema.safeParse(json);
|
|
262
|
+
const parsed = errBody.success ? errBody.data : void 0;
|
|
263
|
+
throw new SmoobuApiError(
|
|
264
|
+
res.status,
|
|
265
|
+
`Smoobu ${method} ${path} failed (${res.status}): ${parsed?.detail || parsed?.title || res.statusText}`,
|
|
266
|
+
parsed,
|
|
267
|
+
{ retryAfterMs: res.status === 429 ? retryDelay(res, attempt) : void 0 }
|
|
268
|
+
);
|
|
269
|
+
}
|
|
270
|
+
const result = schema.safeParse(json);
|
|
271
|
+
if (!result.success) throw new SmoobuResponseShapeError(path, result.error.issues);
|
|
272
|
+
return result.data;
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
};
|
|
276
|
+
var backoff = (attempt) => 500 * 2 ** attempt;
|
|
277
|
+
function retryDelay(res, attempt) {
|
|
278
|
+
const header = Number(res.headers.get("X-RateLimit-Retry-After"));
|
|
279
|
+
if (res.status === 429 && Number.isFinite(header) && header > 0) {
|
|
280
|
+
const ms = header > 1e9 ? header * 1e3 - Date.now() : header * 1e3;
|
|
281
|
+
if (ms > 0) return Math.min(ms, 6e4);
|
|
282
|
+
}
|
|
283
|
+
return backoff(attempt);
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
// src/html.ts
|
|
287
|
+
var ENTITIES = {
|
|
288
|
+
amp: "&",
|
|
289
|
+
lt: "<",
|
|
290
|
+
gt: ">",
|
|
291
|
+
quot: '"',
|
|
292
|
+
apos: "'",
|
|
293
|
+
nbsp: " "
|
|
294
|
+
};
|
|
295
|
+
function htmlToText(html) {
|
|
296
|
+
return html.replace(/<(script|style)[^>]*>[\s\S]*?<\/\1>/gi, "").replace(/<br\s*\/?>/gi, "\n").replace(/<\/(p|div|li|tr|h[1-6])>/gi, "\n").replace(/<li[^>]*>/gi, "- ").replace(/<[^>]+>/g, "").replace(/&(#x[0-9a-f]+|#\d+|[a-z]+);/gi, (m, e) => {
|
|
297
|
+
if (e[0] === "#") {
|
|
298
|
+
const code = e[1]?.toLowerCase() === "x" ? parseInt(e.slice(2), 16) : parseInt(e.slice(1), 10);
|
|
299
|
+
return Number.isFinite(code) ? String.fromCodePoint(code) : m;
|
|
300
|
+
}
|
|
301
|
+
return ENTITIES[e.toLowerCase()] ?? m;
|
|
302
|
+
}).replace(/[ \t]+\n/g, "\n").replace(/\n{3,}/g, "\n\n").trim();
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
// src/mappers.ts
|
|
306
|
+
function toLocalDateTime(value) {
|
|
307
|
+
if (!value) return null;
|
|
308
|
+
const m = /^(\d{4}-\d{2}-\d{2})[ T](\d{2}:\d{2}:\d{2})$/.exec(value.trim());
|
|
309
|
+
return m ? `${m[1]}T${m[2]}` : null;
|
|
310
|
+
}
|
|
311
|
+
var emptyToNull = (v) => v ? v : null;
|
|
312
|
+
function toMessage(reservationId, m) {
|
|
313
|
+
const html = emptyToNull(m.htmlMessage ?? m.messageHtml);
|
|
314
|
+
return {
|
|
315
|
+
id: m.id,
|
|
316
|
+
reservationId,
|
|
317
|
+
// Smoobu: 1 = inbox (from guest), 2 = outbox (from host). Unknown types count as outbound.
|
|
318
|
+
direction: m.type === 1 ? "inbound" : "outbound",
|
|
319
|
+
subject: emptyToNull(m.subject),
|
|
320
|
+
text: m.message || (html ? htmlToText(html) : ""),
|
|
321
|
+
html,
|
|
322
|
+
sentAt: toLocalDateTime(m.createdAt)
|
|
323
|
+
};
|
|
324
|
+
}
|
|
325
|
+
function toConversationSummary(t) {
|
|
326
|
+
const latest = t.latest_message;
|
|
327
|
+
const text = latest?.text_content || (latest?.html_content ? htmlToText(latest.html_content) : "");
|
|
328
|
+
return {
|
|
329
|
+
reservationId: t.booking.id,
|
|
330
|
+
guestName: emptyToNull(t.booking.guest_name),
|
|
331
|
+
property: t.apartment ? { id: t.apartment.id, name: emptyToNull(t.apartment.name) } : null,
|
|
332
|
+
lastMessage: latest ? {
|
|
333
|
+
id: latest.id,
|
|
334
|
+
subject: emptyToNull(latest.subject),
|
|
335
|
+
preview: text.slice(0, 200),
|
|
336
|
+
sentAt: toLocalDateTime(latest.created_at)
|
|
337
|
+
} : null
|
|
338
|
+
};
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
// src/smoobu.ts
|
|
342
|
+
var Smoobu = class {
|
|
343
|
+
client;
|
|
344
|
+
constructor(options) {
|
|
345
|
+
this.client = options instanceof SmoobuClient ? options : new SmoobuClient(options);
|
|
346
|
+
}
|
|
347
|
+
/** The account the API key belongs to (GET /api/me). The cheapest credentials check. */
|
|
348
|
+
async getAccount() {
|
|
349
|
+
const me = await this.client.getMe();
|
|
350
|
+
return {
|
|
351
|
+
id: me.id,
|
|
352
|
+
firstName: me.firstName ?? null,
|
|
353
|
+
lastName: me.lastName ?? null,
|
|
354
|
+
email: me.email ?? null
|
|
355
|
+
};
|
|
356
|
+
}
|
|
357
|
+
messages = {
|
|
358
|
+
/** Conversations, most recent first, with the latest message of each (GET /api/threads). */
|
|
359
|
+
listConversations: async (params = {}) => {
|
|
360
|
+
const res = await this.client.listThreads({
|
|
361
|
+
page: params.page,
|
|
362
|
+
pageSize: params.pageSize,
|
|
363
|
+
apartmentIds: params.propertyIds
|
|
364
|
+
});
|
|
365
|
+
return {
|
|
366
|
+
items: res.threads.map(toConversationSummary),
|
|
367
|
+
page: res.page_number,
|
|
368
|
+
pageSize: res.page_size,
|
|
369
|
+
pageCount: res.page_count,
|
|
370
|
+
total: res.total_threads,
|
|
371
|
+
unreadMessages: res.unread_messages ?? null
|
|
372
|
+
};
|
|
373
|
+
},
|
|
374
|
+
/** Messages of one reservation, oldest first. Smoobu fixes the page size (25). */
|
|
375
|
+
list: async (reservationId, params = {}) => {
|
|
376
|
+
const res = await this.client.listReservationMessages(reservationId, params);
|
|
377
|
+
return {
|
|
378
|
+
items: res.messages.map((m) => toMessage(reservationId, m)),
|
|
379
|
+
page: res.page,
|
|
380
|
+
pageSize: res.page_size,
|
|
381
|
+
pageCount: res.page_count,
|
|
382
|
+
total: res.total_items
|
|
383
|
+
};
|
|
384
|
+
},
|
|
385
|
+
/**
|
|
386
|
+
* Sends a message to the guest, or an internal host-only note (audience: 'internal').
|
|
387
|
+
* Smoobu returns no message id: list the reservation's messages to see it.
|
|
388
|
+
*/
|
|
389
|
+
send: async ({ reservationId, body, subject, audience = "guest" }) => {
|
|
390
|
+
const payload = { messageBody: body, ...subject ? { subject } : {} };
|
|
391
|
+
if (audience === "internal") {
|
|
392
|
+
await this.client.sendMessageToHost(reservationId, { ...payload, internal: true });
|
|
393
|
+
} else {
|
|
394
|
+
await this.client.sendMessageToGuest(reservationId, payload);
|
|
395
|
+
}
|
|
396
|
+
return { accepted: true };
|
|
397
|
+
}
|
|
398
|
+
};
|
|
399
|
+
};
|
|
400
|
+
|
|
401
|
+
// src/types.ts
|
|
402
|
+
import { z as z2 } from "zod";
|
|
403
|
+
var messageDirectionSchema = z2.enum(["inbound", "outbound"]);
|
|
404
|
+
var localDateTime = z2.iso.datetime({ local: true });
|
|
405
|
+
var messageSchema = z2.object({
|
|
406
|
+
id: z2.number().int(),
|
|
407
|
+
reservationId: z2.number().int(),
|
|
408
|
+
direction: messageDirectionSchema,
|
|
409
|
+
subject: z2.string().nullable(),
|
|
410
|
+
/** Plain-text body (derived from the HTML body when Smoobu only provides that). */
|
|
411
|
+
text: z2.string(),
|
|
412
|
+
/** Raw HTML body when present. Guest-controlled: sanitise before rendering. */
|
|
413
|
+
html: z2.string().nullable(),
|
|
414
|
+
sentAt: localDateTime.nullable()
|
|
415
|
+
});
|
|
416
|
+
var conversationSummarySchema = z2.object({
|
|
417
|
+
/** null for inquiries that have no reservation yet. */
|
|
418
|
+
reservationId: z2.number().int().nullable(),
|
|
419
|
+
guestName: z2.string().nullable(),
|
|
420
|
+
property: z2.object({ id: z2.number().int().nullable(), name: z2.string().nullable() }).nullable(),
|
|
421
|
+
lastMessage: z2.object({
|
|
422
|
+
id: z2.number().int(),
|
|
423
|
+
subject: z2.string().nullable(),
|
|
424
|
+
preview: z2.string(),
|
|
425
|
+
sentAt: localDateTime.nullable()
|
|
426
|
+
}).nullable()
|
|
427
|
+
});
|
|
428
|
+
var pageSchema = (item) => z2.object({
|
|
429
|
+
items: z2.array(item),
|
|
430
|
+
page: z2.number().int(),
|
|
431
|
+
pageSize: z2.number().int(),
|
|
432
|
+
pageCount: z2.number().int(),
|
|
433
|
+
total: z2.number().int()
|
|
434
|
+
});
|
|
435
|
+
var conversationPageSchema = pageSchema(conversationSummarySchema).extend({
|
|
436
|
+
unreadMessages: z2.number().int().nullable()
|
|
437
|
+
});
|
|
438
|
+
var messagePageSchema = pageSchema(messageSchema);
|
|
439
|
+
var messageAudienceSchema = z2.enum(["guest", "internal"]);
|
|
440
|
+
export {
|
|
441
|
+
Smoobu,
|
|
442
|
+
SmoobuApiError,
|
|
443
|
+
SmoobuClient,
|
|
444
|
+
SmoobuResponseShapeError,
|
|
445
|
+
canonicalQuery,
|
|
446
|
+
conversationPageSchema,
|
|
447
|
+
conversationSummarySchema,
|
|
448
|
+
htmlToText,
|
|
449
|
+
messageAudienceSchema,
|
|
450
|
+
messageDirectionSchema,
|
|
451
|
+
messagePageSchema,
|
|
452
|
+
messageSchema,
|
|
453
|
+
pageSchema,
|
|
454
|
+
signRequest,
|
|
455
|
+
toConversationSummary,
|
|
456
|
+
toLocalDateTime,
|
|
457
|
+
toMessage,
|
|
458
|
+
wire_exports as wire
|
|
459
|
+
};
|
|
460
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/auth.ts","../src/wire.ts","../src/client.ts","../src/html.ts","../src/mappers.ts","../src/smoobu.ts","../src/types.ts"],"sourcesContent":["import { createHash, createHmac, randomUUID } from 'node:crypto';\n\n/**\n * Smoobu HMAC request signing (https://docs.smoobu.com/ → Authentication).\n *\n * canonical = METHOD \\n PATH \\n QUERY \\n TIMESTAMP \\n NONCE \\n sha256hex(BODY) \\n API_KEY\n * X-Signature = base64(hmacSha256(secret, canonical))\n *\n * QUERY is sorted and RFC 3986 encoded (spaces → %20, brackets → %5B%5D); it is an empty line\n * when there are no parameters. The exact same query string must be sent on the wire.\n */\n\nexport type QueryValue =\n string | number | boolean | undefined | null | readonly (string | number)[];\nexport type Query = Record<string, QueryValue>;\n\n/** encodeURIComponent leaves !'()* untouched; RFC 3986 reserves them. */\nconst rfc3986 = (value: string) =>\n encodeURIComponent(value).replace(\n /[!'()*]/g,\n (c) => `%${c.charCodeAt(0).toString(16).toUpperCase()}`,\n );\n\n/** Builds the sorted, RFC 3986-encoded query string (without the leading `?`). */\nexport function canonicalQuery(query: Query = {}): string {\n const pairs: [string, string][] = [];\n for (const [key, value] of Object.entries(query)) {\n if (value === undefined || value === null) continue;\n if (Array.isArray(value)) {\n for (const item of value) pairs.push([`${key}[]`, String(item)]);\n } else {\n pairs.push([key, String(value)]);\n }\n }\n return pairs\n .map(([k, v]) => [rfc3986(k), rfc3986(v)] as const)\n .sort(([ak, av], [bk, bv]) => (ak === bk ? (av < bv ? -1 : 1) : ak < bk ? -1 : 1))\n .map(([k, v]) => `${k}=${v}`)\n .join('&');\n}\n\nexport interface SignInput {\n method: string;\n path: string;\n /** Already canonicalised query string (see canonicalQuery). */\n query: string;\n /** Raw request body exactly as sent ('' for none). */\n body: string;\n apiKey: string;\n apiSecret: string;\n /** Injectable for tests. */\n timestamp?: string;\n nonce?: string;\n}\n\nexport function signRequest(input: SignInput): Record<string, string> {\n // ISO 8601 UTC without milliseconds, e.g. 2026-04-01T12:00:00Z\n const timestamp = input.timestamp ?? new Date().toISOString().replace(/\\.\\d{3}Z$/, 'Z');\n const nonce = input.nonce ?? randomUUID();\n const bodyHash = createHash('sha256').update(input.body).digest('hex');\n const canonical = [\n input.method.toUpperCase(),\n input.path,\n input.query,\n timestamp,\n nonce,\n bodyHash,\n input.apiKey,\n ].join('\\n');\n const signature = createHmac('sha256', input.apiSecret).update(canonical).digest('base64');\n return {\n 'X-API-Key': input.apiKey,\n 'X-Timestamp': timestamp,\n 'X-Nonce': nonce,\n 'X-Signature': signature,\n };\n}\n","import { z } from 'zod';\n\n/**\n * Raw Smoobu wire formats. These mirror Smoobu's JSON exactly — including its inconsistent\n * casing — and are deliberately lenient (loose objects, optional fields): the docs are known to\n * disagree with real payloads. Exported as `wire` for advanced use; prefer the domain types\n * (types.ts) produced by mappers.ts.\n */\n\nexport const smoobuErrorSchema = z.looseObject({\n status: z.number().optional(),\n title: z.string().optional(),\n detail: z.string().optional(),\n validation_messages: z.record(z.string(), z.unknown()).optional(),\n});\nexport type SmoobuErrorBody = z.infer<typeof smoobuErrorSchema>;\n\nexport const smoobuUserSchema = z.looseObject({\n id: z.number(),\n firstName: z.string().nullish(),\n lastName: z.string().nullish(),\n email: z.string().nullish(),\n});\nexport type SmoobuUser = z.infer<typeof smoobuUserSchema>;\n\nexport const smoobuMessageSchema = z.looseObject({\n id: z.number(),\n subject: z.string().nullish(),\n message: z.string().nullish(),\n // The docs' example says `messageHtml`, the field table says `htmlMessage`: accept both.\n messageHtml: z.string().nullish(),\n htmlMessage: z.string().nullish(),\n /** 1 = inbox (received from the guest), 2 = outbox (sent by the host). */\n type: z.number(),\n /** \"YYYY-MM-DD HH:MM:SS\" (observed; undocumented), timezone not stated. */\n createdAt: z.string().nullish(),\n});\nexport type SmoobuMessage = z.infer<typeof smoobuMessageSchema>;\n\nexport const smoobuMessagesPageSchema = z.looseObject({\n page_count: z.number(),\n page_size: z.number(),\n total_items: z.number(),\n page: z.number(),\n messages: z.array(smoobuMessageSchema),\n});\nexport type SmoobuMessagesPage = z.infer<typeof smoobuMessagesPageSchema>;\n\nexport const smoobuThreadSchema = z.looseObject({\n // Observed in production: some threads (inquiries?) have `booking.id` and `apartment.id` = null.\n booking: z.looseObject({ id: z.number().nullable(), guest_name: z.string().nullish() }),\n apartment: z.looseObject({ id: z.number().nullable(), name: z.string().nullish() }).nullish(),\n latest_message: z\n .looseObject({\n id: z.number(),\n subject: z.string().nullish(),\n text_content: z.string().nullish(),\n html_content: z.string().nullish(),\n /** \"YYYY-MM-DD HH:MM:SS\", timezone not documented. */\n created_at: z.string().nullish(),\n })\n .nullish(),\n});\nexport type SmoobuThread = z.infer<typeof smoobuThreadSchema>;\n\nexport const smoobuThreadsPageSchema = z.looseObject({\n page_number: z.number(),\n page_size: z.number(),\n page_count: z.number(),\n total_threads: z.number(),\n unread_messages: z.number().nullish(),\n threads: z.array(smoobuThreadSchema),\n});\nexport type SmoobuThreadsPage = z.infer<typeof smoobuThreadsPageSchema>;\n\nexport interface SmoobuSendMessageBody {\n subject?: string;\n /** HTML or plain text. */\n messageBody: string;\n /** Host messages only: hidden from the guest when true. */\n internal?: boolean;\n}\n\n/** Envelope of every webhook call. `data` depends on `action`. */\nexport const smoobuWebhookSchema = z.looseObject({\n action: z.string(),\n user: z.number(),\n data: z.unknown(),\n});\nexport const smoobuNewMessageDataSchema = z.looseObject({\n id: z.number(),\n sender: z.string().nullish(),\n booking: z.looseObject({ id: z.number() }),\n});\n","import type { z } from 'zod';\nimport { canonicalQuery, signRequest, type Query } from './auth';\nimport {\n smoobuErrorSchema,\n smoobuMessagesPageSchema,\n smoobuThreadsPageSchema,\n smoobuUserSchema,\n type SmoobuErrorBody,\n type SmoobuSendMessageBody,\n} from './wire';\n\nexport interface SmoobuClientOptions {\n apiKey: string;\n apiSecret: string;\n baseUrl?: string;\n /** Per-attempt timeout. */\n timeoutMs?: number;\n /** Extra attempts on 429 / 5xx / network errors (GET only: POSTs are not idempotent). */\n maxRetries?: number;\n /** Sent as User-Agent, e.g. `my-app/1.2.3`. */\n userAgent?: string;\n /** Injectable for tests. */\n fetch?: typeof fetch;\n sleep?: (ms: number) => Promise<void>;\n}\n\nexport type SmoobuErrorCode =\n | 'unauthorized'\n | 'forbidden'\n | 'not_found'\n | 'validation'\n | 'rate_limited'\n | 'upstream'\n | 'network';\n\nfunction errorCode(status: number): SmoobuErrorCode {\n if (status === 0) return 'network';\n if (status === 401) return 'unauthorized';\n if (status === 403) return 'forbidden';\n if (status === 404) return 'not_found';\n if (status === 400 || status === 409 || status === 422) return 'validation';\n if (status === 429) return 'rate_limited';\n return 'upstream';\n}\n\n/** Any non-2xx answer (or unreachable API). `status` 0 = network/timeout. */\nexport class SmoobuApiError extends Error {\n override readonly name = 'SmoobuApiError';\n readonly code: SmoobuErrorCode;\n /** Worth retrying later (rate limit, 5xx, network). */\n readonly retryable: boolean;\n constructor(\n readonly status: number,\n message: string,\n readonly body?: SmoobuErrorBody,\n options?: ErrorOptions & { retryAfterMs?: number },\n ) {\n super(message, options);\n this.code = errorCode(status);\n this.retryable = status === 0 || status === 429 || status >= 500;\n this.retryAfterMs = options?.retryAfterMs;\n }\n /** For rate limits: how long until the window resets, when Smoobu says so. */\n readonly retryAfterMs: number | undefined;\n}\n\n/** Smoobu answered 2xx but the payload did not match the expected shape. */\nexport class SmoobuResponseShapeError extends Error {\n override readonly name = 'SmoobuResponseShapeError';\n constructor(\n readonly path: string,\n readonly issues: z.core.$ZodIssue[],\n ) {\n super(`Unexpected Smoobu response for ${path}`);\n }\n}\n\ninterface RequestOptions<T> {\n query?: Query;\n body?: unknown;\n schema: z.ZodType<T>;\n}\n\n/**\n * Low-level, typed Smoobu HTTP client. One method per endpoint, returns validated *wire* types.\n * Knows nothing about the domain model (see `Smoobu` for that).\n */\nexport class SmoobuClient {\n private readonly baseUrl: string;\n private readonly timeoutMs: number;\n private readonly maxRetries: number;\n private readonly fetchFn: typeof fetch;\n private readonly sleep: (ms: number) => Promise<void>;\n\n constructor(private readonly opts: SmoobuClientOptions) {\n this.baseUrl = (opts.baseUrl ?? 'https://login.smoobu.com').replace(/\\/+$/, '');\n this.timeoutMs = opts.timeoutMs ?? 15_000;\n this.maxRetries = opts.maxRetries ?? 2;\n this.fetchFn = opts.fetch ?? fetch;\n this.sleep = opts.sleep ?? ((ms) => new Promise((r) => setTimeout(r, ms)));\n }\n\n // --- Endpoints -------------------------------------------------------------------------------\n\n /** GET /api/me — the account the API key belongs to. Cheapest connectivity check. */\n getMe() {\n return this.request('GET', '/api/me', { schema: smoobuUserSchema });\n }\n\n /** GET /api/threads — conversation list with the latest message of each booking. */\n listThreads(params: { page?: number; pageSize?: number; apartmentIds?: number[] } = {}) {\n return this.request('GET', '/api/threads', {\n query: {\n page_number: params.page,\n page_size: params.pageSize,\n apartments: params.apartmentIds,\n },\n schema: smoobuThreadsPageSchema,\n });\n }\n\n /** GET /api/reservations/{id}/messages */\n listReservationMessages(\n reservationId: number,\n params: { page?: number; onlyRelatedToGuest?: boolean } = {},\n ) {\n return this.request('GET', `/api/reservations/${reservationId}/messages`, {\n query: { page: params.page, onlyRelatedToGuest: params.onlyRelatedToGuest },\n schema: smoobuMessagesPageSchema,\n });\n }\n\n /** POST /api/reservations/{id}/messages/send-message-to-guest (no message id is returned). */\n sendMessageToGuest(reservationId: number, body: Omit<SmoobuSendMessageBody, 'internal'>) {\n return this.request(\n 'POST',\n `/api/reservations/${reservationId}/messages/send-message-to-guest`,\n { body, schema: smoobuErrorSchema },\n );\n }\n\n /** POST /api/reservations/{id}/messages/send-message-to-host (`internal` hides it from the guest). */\n sendMessageToHost(reservationId: number, body: SmoobuSendMessageBody) {\n return this.request(\n 'POST',\n `/api/reservations/${reservationId}/messages/send-message-to-host`,\n {\n body,\n schema: smoobuErrorSchema,\n },\n );\n }\n\n // --- Transport -------------------------------------------------------------------------------\n\n private async request<T>(\n method: 'GET' | 'POST' | 'PATCH' | 'DELETE',\n path: string,\n { query, body, schema }: RequestOptions<T>,\n ): Promise<T> {\n const qs = canonicalQuery(query);\n const rawBody = body === undefined ? '' : JSON.stringify(body);\n const url = `${this.baseUrl}${path}${qs ? `?${qs}` : ''}`;\n const retries = method === 'GET' ? this.maxRetries : 0;\n\n for (let attempt = 0; ; attempt++) {\n let res: Response;\n try {\n // Re-sign on every attempt: nonces are single-use.\n res = await this.fetchFn(url, {\n method,\n headers: {\n Accept: 'application/json',\n ...(this.opts.userAgent ? { 'User-Agent': this.opts.userAgent } : {}),\n ...(rawBody ? { 'Content-Type': 'application/json' } : {}),\n ...signRequest({\n method,\n path,\n query: qs,\n body: rawBody,\n apiKey: this.opts.apiKey,\n apiSecret: this.opts.apiSecret,\n }),\n },\n body: rawBody || undefined,\n signal: AbortSignal.timeout(this.timeoutMs),\n });\n } catch (err) {\n if (attempt < retries) {\n await this.sleep(backoff(attempt));\n continue;\n }\n throw new SmoobuApiError(0, `Smoobu unreachable: ${(err as Error).message}`, undefined, {\n cause: err,\n });\n }\n\n const json: unknown =\n res.status === 204 ? undefined : await res.json().catch(() => undefined);\n\n if (!res.ok) {\n const retryable = res.status === 429 || res.status >= 500;\n if (retryable && attempt < retries) {\n await this.sleep(retryDelay(res, attempt));\n continue;\n }\n const errBody = smoobuErrorSchema.safeParse(json);\n const parsed = errBody.success ? errBody.data : undefined;\n throw new SmoobuApiError(\n res.status,\n `Smoobu ${method} ${path} failed (${res.status}): ${parsed?.detail || parsed?.title || res.statusText}`,\n parsed,\n { retryAfterMs: res.status === 429 ? retryDelay(res, attempt) : undefined },\n );\n }\n\n const result = schema.safeParse(json);\n if (!result.success) throw new SmoobuResponseShapeError(path, result.error.issues);\n return result.data;\n }\n }\n}\n\nconst backoff = (attempt: number) => 500 * 2 ** attempt;\n\n/** X-RateLimit-Retry-After is documented as the window's Unix expiry timestamp. */\nfunction retryDelay(res: Response, attempt: number): number {\n const header = Number(res.headers.get('X-RateLimit-Retry-After'));\n if (res.status === 429 && Number.isFinite(header) && header > 0) {\n const ms = header > 1e9 ? header * 1000 - Date.now() : header * 1000;\n if (ms > 0) return Math.min(ms, 60_000);\n }\n return backoff(attempt);\n}\n","/**\n * Minimal, dependency-free HTML → plain text for message bodies (no DOM available in Node).\n * Good enough for chat messages: keeps line structure, drops markup, decodes common entities.\n */\nconst ENTITIES: Record<string, string> = {\n amp: '&',\n lt: '<',\n gt: '>',\n quot: '\"',\n apos: \"'\",\n nbsp: ' ',\n};\n\nexport function htmlToText(html: string): string {\n return html\n .replace(/<(script|style)[^>]*>[\\s\\S]*?<\\/\\1>/gi, '')\n .replace(/<br\\s*\\/?>/gi, '\\n')\n .replace(/<\\/(p|div|li|tr|h[1-6])>/gi, '\\n')\n .replace(/<li[^>]*>/gi, '- ')\n .replace(/<[^>]+>/g, '')\n .replace(/&(#x[0-9a-f]+|#\\d+|[a-z]+);/gi, (m, e: string) => {\n if (e[0] === '#') {\n const code =\n e[1]?.toLowerCase() === 'x' ? parseInt(e.slice(2), 16) : parseInt(e.slice(1), 10);\n return Number.isFinite(code) ? String.fromCodePoint(code) : m;\n }\n return ENTITIES[e.toLowerCase()] ?? m;\n })\n .replace(/[ \\t]+\\n/g, '\\n')\n .replace(/\\n{3,}/g, '\\n\\n')\n .trim();\n}\n","import { htmlToText } from './html';\nimport type { ConversationSummary, Message } from './types';\nimport type { SmoobuMessage, SmoobuThread } from './wire';\n\n/** \"YYYY-MM-DD HH:MM:SS\" → \"YYYY-MM-DDTHH:MM:SS\"; anything unexpected → null. */\nexport function toLocalDateTime(value: string | null | undefined): string | null {\n if (!value) return null;\n const m = /^(\\d{4}-\\d{2}-\\d{2})[ T](\\d{2}:\\d{2}:\\d{2})$/.exec(value.trim());\n return m ? `${m[1]}T${m[2]}` : null;\n}\n\nconst emptyToNull = (v: string | null | undefined) => (v ? v : null);\n\nexport function toMessage(reservationId: number, m: SmoobuMessage): Message {\n const html = emptyToNull(m.htmlMessage ?? m.messageHtml);\n return {\n id: m.id,\n reservationId,\n // Smoobu: 1 = inbox (from guest), 2 = outbox (from host). Unknown types count as outbound.\n direction: m.type === 1 ? 'inbound' : 'outbound',\n subject: emptyToNull(m.subject),\n text: m.message || (html ? htmlToText(html) : ''),\n html,\n sentAt: toLocalDateTime(m.createdAt),\n };\n}\n\nexport function toConversationSummary(t: SmoobuThread): ConversationSummary {\n const latest = t.latest_message;\n const text =\n latest?.text_content || (latest?.html_content ? htmlToText(latest.html_content) : '');\n return {\n reservationId: t.booking.id,\n guestName: emptyToNull(t.booking.guest_name),\n property: t.apartment ? { id: t.apartment.id, name: emptyToNull(t.apartment.name) } : null,\n lastMessage: latest\n ? {\n id: latest.id,\n subject: emptyToNull(latest.subject),\n preview: text.slice(0, 200),\n sentAt: toLocalDateTime(latest.created_at),\n }\n : null,\n };\n}\n","import { SmoobuClient, type SmoobuClientOptions } from './client';\nimport { toConversationSummary, toMessage } from './mappers';\nimport type { Account, ConversationPage, MessagePage, SendMessageInput } from './types';\n\n/**\n * High-level Smoobu API: speaks the clean domain model (types.ts). Use `.client` for raw,\n * endpoint-level access to anything not covered here yet.\n */\nexport class Smoobu {\n readonly client: SmoobuClient;\n\n constructor(options: SmoobuClientOptions | SmoobuClient) {\n this.client = options instanceof SmoobuClient ? options : new SmoobuClient(options);\n }\n\n /** The account the API key belongs to (GET /api/me). The cheapest credentials check. */\n async getAccount(): Promise<Account> {\n const me = await this.client.getMe();\n return {\n id: me.id,\n firstName: me.firstName ?? null,\n lastName: me.lastName ?? null,\n email: me.email ?? null,\n };\n }\n\n readonly messages = {\n /** Conversations, most recent first, with the latest message of each (GET /api/threads). */\n listConversations: async (\n params: { page?: number; pageSize?: number; propertyIds?: number[] } = {},\n ): Promise<ConversationPage> => {\n const res = await this.client.listThreads({\n page: params.page,\n pageSize: params.pageSize,\n apartmentIds: params.propertyIds,\n });\n return {\n items: res.threads.map(toConversationSummary),\n page: res.page_number,\n pageSize: res.page_size,\n pageCount: res.page_count,\n total: res.total_threads,\n unreadMessages: res.unread_messages ?? null,\n };\n },\n\n /** Messages of one reservation, oldest first. Smoobu fixes the page size (25). */\n list: async (\n reservationId: number,\n params: { page?: number; onlyRelatedToGuest?: boolean } = {},\n ): Promise<MessagePage> => {\n const res = await this.client.listReservationMessages(reservationId, params);\n return {\n items: res.messages.map((m) => toMessage(reservationId, m)),\n page: res.page,\n pageSize: res.page_size,\n pageCount: res.page_count,\n total: res.total_items,\n };\n },\n\n /**\n * Sends a message to the guest, or an internal host-only note (audience: 'internal').\n * Smoobu returns no message id: list the reservation's messages to see it.\n */\n send: async ({ reservationId, body, subject, audience = 'guest' }: SendMessageInput) => {\n const payload = { messageBody: body, ...(subject ? { subject } : {}) };\n if (audience === 'internal') {\n await this.client.sendMessageToHost(reservationId, { ...payload, internal: true });\n } else {\n await this.client.sendMessageToGuest(reservationId, payload);\n }\n return { accepted: true as const };\n },\n };\n}\n","import { z } from 'zod';\n\n/**\n * Clean, provider-neutral messaging model. Smoobu's wire format (see wire.ts) is mapped to these\n * shapes by mappers.ts so consumers never deal with its inconsistent casing, integer enums,\n * naive dates or empty strings.\n *\n * Timestamps are ISO 8601 *local* date-times without offset (`2026-11-17T10:20:27`): Smoobu\n * returns naive \"YYYY-MM-DD HH:MM:SS\" values and does not document their timezone.\n */\n\n/** inbound = written by the guest, outbound = written by the host (or an automation). */\nexport const messageDirectionSchema = z.enum(['inbound', 'outbound']);\nexport type MessageDirection = z.infer<typeof messageDirectionSchema>;\n\nconst localDateTime = z.iso.datetime({ local: true });\n\nexport const messageSchema = z.object({\n id: z.number().int(),\n reservationId: z.number().int(),\n direction: messageDirectionSchema,\n subject: z.string().nullable(),\n /** Plain-text body (derived from the HTML body when Smoobu only provides that). */\n text: z.string(),\n /** Raw HTML body when present. Guest-controlled: sanitise before rendering. */\n html: z.string().nullable(),\n sentAt: localDateTime.nullable(),\n});\nexport type Message = z.infer<typeof messageSchema>;\n\n/** One conversation per reservation (or per inquiry, which has no reservation yet). */\nexport const conversationSummarySchema = z.object({\n /** null for inquiries that have no reservation yet. */\n reservationId: z.number().int().nullable(),\n guestName: z.string().nullable(),\n property: z.object({ id: z.number().int().nullable(), name: z.string().nullable() }).nullable(),\n lastMessage: z\n .object({\n id: z.number().int(),\n subject: z.string().nullable(),\n preview: z.string(),\n sentAt: localDateTime.nullable(),\n })\n .nullable(),\n});\nexport type ConversationSummary = z.infer<typeof conversationSummarySchema>;\n\n/** Uniform page envelope (Smoobu uses three different pagination vocabularies). */\nexport const pageSchema = <T extends z.ZodType>(item: T) =>\n z.object({\n items: z.array(item),\n page: z.number().int(),\n pageSize: z.number().int(),\n pageCount: z.number().int(),\n total: z.number().int(),\n });\nexport type Page<T> = {\n items: T[];\n page: number;\n pageSize: number;\n pageCount: number;\n total: number;\n};\n\nexport const conversationPageSchema = pageSchema(conversationSummarySchema).extend({\n unreadMessages: z.number().int().nullable(),\n});\nexport type ConversationPage = z.infer<typeof conversationPageSchema>;\n\nexport const messagePageSchema = pageSchema(messageSchema);\nexport type MessagePage = z.infer<typeof messagePageSchema>;\n\n/** guest = visible to the guest; internal = host-only note on the reservation. */\nexport const messageAudienceSchema = z.enum(['guest', 'internal']);\nexport type MessageAudience = z.infer<typeof messageAudienceSchema>;\n\nexport interface SendMessageInput {\n reservationId: number;\n /** Plain text or HTML. */\n body: string;\n subject?: string;\n /** Default: guest. */\n audience?: MessageAudience;\n}\n\nexport interface Account {\n id: number;\n firstName: string | null;\n lastName: string | null;\n email: string | null;\n}\n"],"mappings":";;;;;;;AAAA,SAAS,YAAY,YAAY,kBAAkB;AAiBnD,IAAM,UAAU,CAAC,UACf,mBAAmB,KAAK,EAAE;AAAA,EACxB;AAAA,EACA,CAAC,MAAM,IAAI,EAAE,WAAW,CAAC,EAAE,SAAS,EAAE,EAAE,YAAY,CAAC;AACvD;AAGK,SAAS,eAAe,QAAe,CAAC,GAAW;AACxD,QAAM,QAA4B,CAAC;AACnC,aAAW,CAAC,KAAK,KAAK,KAAK,OAAO,QAAQ,KAAK,GAAG;AAChD,QAAI,UAAU,UAAa,UAAU,KAAM;AAC3C,QAAI,MAAM,QAAQ,KAAK,GAAG;AACxB,iBAAW,QAAQ,MAAO,OAAM,KAAK,CAAC,GAAG,GAAG,MAAM,OAAO,IAAI,CAAC,CAAC;AAAA,IACjE,OAAO;AACL,YAAM,KAAK,CAAC,KAAK,OAAO,KAAK,CAAC,CAAC;AAAA,IACjC;AAAA,EACF;AACA,SAAO,MACJ,IAAI,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,QAAQ,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAU,EACjD,KA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EAAE,SAAS,GAAG,MAAMA,GAAE,OAAO,EAAE,SAAS,EAAE,CAAC,EAAE,SAAS;AAAA,EAC9F,aAAaA,GACV,OAAO;AAAA,IACN,IAAIA,GAAE,OAAO,EAAE,IAAI;AAAA,IACnB,SAASA,GAAE,OAAO,EAAE,SAAS;AAAA,IAC7B,SAASA,GAAE,OAAO;AAAA,IAClB,QAAQ,cAAc,SAAS;AAAA,EACjC,CAAC,EACA,SAAS;AACd,CAAC;AAIM,IAAM,aAAa,CAAsB,SAC9CA,GAAE,OAAO;AAAA,EACP,OAAOA,GAAE,MAAM,IAAI;AAAA,EACnB,MAAMA,GAAE,OAAO,EAAE,IAAI;AAAA,EACrB,UAAUA,GAAE,OAAO,EAAE,IAAI;AAAA,EACzB,WAAWA,GAAE,OAAO,EAAE,IAAI;AAAA,EAC1B,OAAOA,GAAE,OAAO,EAAE,IAAI;AACxB,CAAC;AASI,IAAM,yBAAyB,WAAW,yBAAyB,EAAE,OAAO;AAAA,EACjF,gBAAgBA,GAAE,OAAO,EAAE,IAAI,EAAE,SAAS;AAC5C,CAAC;AAGM,IAAM,oBAAoB,WAAW,aAAa;AAIlD,IAAM,wBAAwBA,GAAE,KAAK,CAAC,SAAS,UAAU,CAAC;","names":["z"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,48 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@skilder-ai/smoobu",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Typed Smoobu API client (HMAC-signed requests, validated responses, clean domain model).",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/skilder-ai/smoobu.git",
|
|
10
|
+
"directory": "packages/smoobu"
|
|
11
|
+
},
|
|
12
|
+
"homepage": "https://github.com/skilder-ai/smoobu/tree/main/packages/smoobu#readme",
|
|
13
|
+
"keywords": [
|
|
14
|
+
"smoobu",
|
|
15
|
+
"channel-manager",
|
|
16
|
+
"vacation-rental",
|
|
17
|
+
"api-client"
|
|
18
|
+
],
|
|
19
|
+
"engines": {
|
|
20
|
+
"node": ">=22"
|
|
21
|
+
},
|
|
22
|
+
"exports": {
|
|
23
|
+
".": {
|
|
24
|
+
"types": "./dist/index.d.ts",
|
|
25
|
+
"import": "./dist/index.js"
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
"main": "./dist/index.js",
|
|
29
|
+
"types": "./dist/index.d.ts",
|
|
30
|
+
"files": [
|
|
31
|
+
"dist"
|
|
32
|
+
],
|
|
33
|
+
"sideEffects": false,
|
|
34
|
+
"publishConfig": {
|
|
35
|
+
"access": "public"
|
|
36
|
+
},
|
|
37
|
+
"peerDependencies": {
|
|
38
|
+
"zod": "^4.0.0"
|
|
39
|
+
},
|
|
40
|
+
"devDependencies": {
|
|
41
|
+
"zod": "^4.6.7"
|
|
42
|
+
},
|
|
43
|
+
"scripts": {
|
|
44
|
+
"build": "tsup",
|
|
45
|
+
"typecheck": "tsc -p tsconfig.json",
|
|
46
|
+
"test": "vitest run"
|
|
47
|
+
}
|
|
6
48
|
}
|