@curless/hotel-storefront 0.58.2 → 0.60.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/dist/account/fake-mall.d.ts +19 -0
- package/dist/account/fake-mall.d.ts.map +1 -1
- package/dist/account/fake-mall.js +81 -10
- package/dist/account/fake-mall.js.map +1 -1
- package/dist/account/index.d.ts +75 -3
- package/dist/account/index.d.ts.map +1 -1
- package/dist/account/index.js +765 -31
- package/dist/account/index.js.map +1 -1
- package/dist/account/mall.d.ts +3 -1
- package/dist/account/mall.d.ts.map +1 -1
- package/dist/account/mall.js +17 -2
- package/dist/account/mall.js.map +1 -1
- package/dist/account/ota-member.d.ts +72 -0
- package/dist/account/ota-member.d.ts.map +1 -0
- package/dist/account/ota-member.js +127 -0
- package/dist/account/ota-member.js.map +1 -0
- package/dist/account/pages.d.ts +99 -4
- package/dist/account/pages.d.ts.map +1 -1
- package/dist/account/pages.js +221 -16
- package/dist/account/pages.js.map +1 -1
- package/dist/account/requests.d.ts +13 -1
- package/dist/account/requests.d.ts.map +1 -1
- package/dist/account/requests.js +2 -1
- package/dist/account/requests.js.map +1 -1
- package/dist/account/store.d.ts +8 -0
- package/dist/account/store.d.ts.map +1 -1
- package/dist/account/store.js.map +1 -1
- package/dist/aggregate/places.d.ts +10 -0
- package/dist/aggregate/places.d.ts.map +1 -1
- package/dist/aggregate/places.js +21 -0
- package/dist/aggregate/places.js.map +1 -1
- package/dist/card.generated.d.ts +1 -1
- package/dist/card.generated.js +2 -2
- package/dist/card.generated.js.map +1 -1
- package/dist/choices.d.ts +88 -0
- package/dist/choices.d.ts.map +1 -0
- package/dist/choices.js +126 -0
- package/dist/choices.js.map +1 -0
- package/dist/otaless/backend.d.ts +28 -0
- package/dist/otaless/backend.d.ts.map +1 -1
- package/dist/otaless/backend.js +349 -93
- package/dist/otaless/backend.js.map +1 -1
- package/dist/otaless/client.d.ts +46 -4
- package/dist/otaless/client.d.ts.map +1 -1
- package/dist/otaless/client.js +138 -35
- package/dist/otaless/client.js.map +1 -1
- package/dist/otaless/limits.d.ts +58 -0
- package/dist/otaless/limits.d.ts.map +1 -0
- package/dist/otaless/limits.js +132 -0
- package/dist/otaless/limits.js.map +1 -0
- package/dist/otaless/make.d.ts.map +1 -1
- package/dist/otaless/make.js +14 -1
- package/dist/otaless/make.js.map +1 -1
- package/dist/otaless/places.d.ts +40 -4
- package/dist/otaless/places.d.ts.map +1 -1
- package/dist/otaless/places.js +152 -2
- package/dist/otaless/places.js.map +1 -1
- package/dist/present.d.ts +12 -1
- package/dist/present.d.ts.map +1 -1
- package/dist/present.js +27 -1
- package/dist/present.js.map +1 -1
- package/dist/server.d.ts +2 -2
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +53 -35
- package/dist/server.js.map +1 -1
- package/dist/sessions.d.ts +23 -4
- package/dist/sessions.d.ts.map +1 -1
- package/dist/sessions.js +57 -7
- package/dist/sessions.js.map +1 -1
- package/dist/supplier.d.ts +6 -0
- package/dist/supplier.d.ts.map +1 -1
- package/dist/supplier.js.map +1 -1
- package/dist/surface.js +1 -1
- package/dist/surface.js.map +1 -1
- package/dist/tools.d.ts +11 -1
- package/dist/tools.d.ts.map +1 -1
- package/dist/tools.js +424 -169
- package/dist/tools.js.map +1 -1
- package/dist/trip-ids.d.ts +35 -4
- package/dist/trip-ids.d.ts.map +1 -1
- package/dist/trip-ids.js +87 -19
- package/dist/trip-ids.js.map +1 -1
- package/dist/types.d.ts +35 -6
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/otaless/backend.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
|
+
import { addressKey } from '../account/index.js';
|
|
2
|
+
import { cityNames } from '../aggregate/places.js';
|
|
1
3
|
import { DEFAULT_PAGE, MAX_PAGE, notPricedForNoAnswer, partyNeedsOf, } from '../backend.js';
|
|
2
4
|
import { nights as nightsOf } from '../dates.js';
|
|
3
5
|
import { FACILITIES, hasFacility } from '../facilities.js';
|
|
4
6
|
import { money, toMinor } from '../money.js';
|
|
5
7
|
import { nameKey } from '../names.js';
|
|
6
|
-
import { OtalessError } from './client.js';
|
|
7
|
-
import { codeOfCountry, groupsIn, isIn, wantedIn } from './places.js';
|
|
8
|
+
import { CHANNEL_SESSION_EXPIRED, OtalessBusy, OtalessError, } from './client.js';
|
|
9
|
+
import { codeOfCountry, groupNames, groupsIn, hotelsByChineseName, isIn, wantedIn, } from './places.js';
|
|
8
10
|
// The Otaless hotel market on the Otaless hotel backend (robin, 2026-11-03:
|
|
9
11
|
// 「Otaless 切到 curless 的 dev 环境吧,包括 ui,如果没数据就不显示」).
|
|
10
12
|
//
|
|
@@ -34,6 +36,76 @@ export const UNCOUNTED_ROOMS = 99;
|
|
|
34
36
|
const EMPTY_CURRENCY = 'CNY';
|
|
35
37
|
/** How many hotels are remembered between searches, so one can be opened by its id after a restart. */
|
|
36
38
|
const KEPT_HOTELS = 5_000;
|
|
39
|
+
/**
|
|
40
|
+
* The most of a place's words sent to the backend, in characters (2026-11-09
|
|
41
|
+
* audit, C6): they went as they came - to the request body's 1 MB - into the
|
|
42
|
+
* request, the backend's logs and our cache's keys. A place is a few words.
|
|
43
|
+
*/
|
|
44
|
+
export const MAX_PLACE = 200;
|
|
45
|
+
/**
|
|
46
|
+
* A trip's rooms are priced this many at a time, and all within this long
|
|
47
|
+
* (2026-11-09 audit, C11). One after another, a trip of six with the backend
|
|
48
|
+
* slow was six times two time limits - longer than a host waits for an answer.
|
|
49
|
+
* A room not priced by then is said as one the group gave no price for in time.
|
|
50
|
+
*/
|
|
51
|
+
export const QUOTE_PARALLEL = 4;
|
|
52
|
+
export const QUOTE_DEADLINE_MS = 15_000;
|
|
53
|
+
/** How many room names are remembered, to name a room its group did not price in time. */
|
|
54
|
+
const KEPT_ROOM_NAMES = 5_000;
|
|
55
|
+
/** Who a read is for, as the limits count it (limits.ts): the conversation, and its network by its /64. */
|
|
56
|
+
const callerOf = (who) => who
|
|
57
|
+
? {
|
|
58
|
+
conversation: who.sessionId,
|
|
59
|
+
...(who.ip ? { address: addressKey(who.ip) } : {}),
|
|
60
|
+
}
|
|
61
|
+
: undefined;
|
|
62
|
+
/** "a, b and c" - "a and b" - "a". */
|
|
63
|
+
const listAnd = (xs) => xs.length > 1 ? `${xs.slice(0, -1).join(', ')} and ${xs.at(-1)}` : (xs[0] ?? '');
|
|
64
|
+
/**
|
|
65
|
+
* Runs `tasks`, `parallel` at a time, until every one is done or `deadlineMs`
|
|
66
|
+
* has passed - whichever comes first. A task not started by then is never
|
|
67
|
+
* started; one still running is left to finish, and what it finds is only
|
|
68
|
+
* the client's cache's. A task's own fault before then is thrown, as one
|
|
69
|
+
* line's was when they ran in turn.
|
|
70
|
+
*/
|
|
71
|
+
const within = (tasks, parallel, deadlineMs) => new Promise((resolve, reject) => {
|
|
72
|
+
let next = 0;
|
|
73
|
+
let running = 0;
|
|
74
|
+
let over = false;
|
|
75
|
+
const end = (err) => {
|
|
76
|
+
if (over)
|
|
77
|
+
return;
|
|
78
|
+
over = true;
|
|
79
|
+
clearTimeout(timer);
|
|
80
|
+
if (err === undefined)
|
|
81
|
+
resolve();
|
|
82
|
+
else
|
|
83
|
+
reject(err);
|
|
84
|
+
};
|
|
85
|
+
const timer = setTimeout(() => end(), deadlineMs);
|
|
86
|
+
timer.unref?.();
|
|
87
|
+
const start = () => {
|
|
88
|
+
while (!over && running < Math.max(1, parallel) && next < tasks.length) {
|
|
89
|
+
const task = tasks[next++];
|
|
90
|
+
if (!task)
|
|
91
|
+
continue;
|
|
92
|
+
running += 1;
|
|
93
|
+
task().then(() => {
|
|
94
|
+
running -= 1;
|
|
95
|
+
start();
|
|
96
|
+
}, (err) => {
|
|
97
|
+
running -= 1;
|
|
98
|
+
if (over)
|
|
99
|
+
console.error('[otaless] a trip line failed after its time:', err);
|
|
100
|
+
else
|
|
101
|
+
end(err ?? new Error('a trip line failed'));
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
if (next >= tasks.length && running === 0)
|
|
105
|
+
end();
|
|
106
|
+
};
|
|
107
|
+
start();
|
|
108
|
+
});
|
|
37
109
|
const refusal = (code, message) => Object.assign(new Error(message), { code });
|
|
38
110
|
/** An amount the backend sends as a number or as a decimal string (`BigDecimal`). */
|
|
39
111
|
const num = (v) => {
|
|
@@ -70,6 +142,18 @@ export const createOtalessHotels = (opts) => {
|
|
|
70
142
|
/** Every group the backend has named in an answer, beyond the configured ones. */
|
|
71
143
|
const seen = new Set();
|
|
72
144
|
const hotels = new Map();
|
|
145
|
+
/** Room names by id, as rooms were read - to name one its group did not price in time. */
|
|
146
|
+
const roomNames = new Map();
|
|
147
|
+
/**
|
|
148
|
+
* Why a read was not sent (`OtalessBusy`), as the model is told it - a
|
|
149
|
+
* limit of ours, said as ours (C6): not the group's silence, and nothing
|
|
150
|
+
* about whether it has hotels or rooms.
|
|
151
|
+
*/
|
|
152
|
+
const heldWhy = (by) => by === 'conversation'
|
|
153
|
+
? `this conversation asked for more hotel searches and prices in the last minute than ${opts.brand} passes on to the hotel groups`
|
|
154
|
+
: by === 'address'
|
|
155
|
+
? `more hotel searches and prices were asked for from this network in the last minute than ${opts.brand} passes on to the hotel groups`
|
|
156
|
+
: `${opts.brand} is already passing on as many requests to the hotel groups as it can just now`;
|
|
73
157
|
const kept = opts.state?.read();
|
|
74
158
|
for (const h of kept?.hotels ?? [])
|
|
75
159
|
if (h && typeof h.id === 'string')
|
|
@@ -130,6 +214,8 @@ export const createOtalessHotels = (opts) => {
|
|
|
130
214
|
...(code ? { supplier: code } : {}),
|
|
131
215
|
city,
|
|
132
216
|
cityId: city.toLowerCase().replace(/\s+/g, '-'),
|
|
217
|
+
// The city in the card's language where it is one this market knows (robin 11-09).
|
|
218
|
+
...(cityNames(city) ? { names: { city: cityNames(city) } } : {}),
|
|
133
219
|
...(cc ? { countryCode: cc } : {}),
|
|
134
220
|
...(countryName ? { country: countryName } : {}),
|
|
135
221
|
...(text(w.address) ? { address: text(w.address) } : {}),
|
|
@@ -180,6 +266,20 @@ export const createOtalessHotels = (opts) => {
|
|
|
180
266
|
uncounted: true,
|
|
181
267
|
};
|
|
182
268
|
};
|
|
269
|
+
/**
|
|
270
|
+
* The hotels seen that a name fits: the ones whose name holds it - or, for a
|
|
271
|
+
* name in Chinese that none holds, the ones it names by its words (亚朵上海外滩
|
|
272
|
+
* is "Atour Hotel Shanghai Bund", `hotelsByChineseName`). Only the hotels
|
|
273
|
+
* seen: nothing is asked of the backend.
|
|
274
|
+
*/
|
|
275
|
+
const fitting = (ref) => {
|
|
276
|
+
const key = nameKey(ref);
|
|
277
|
+
if (!key)
|
|
278
|
+
return [];
|
|
279
|
+
const all = [...hotels.values()];
|
|
280
|
+
const like = all.filter((h) => nameKey(h.name).includes(key));
|
|
281
|
+
return like.length ? like : hotelsByChineseName(ref, all, opts.groups ?? []);
|
|
282
|
+
};
|
|
183
283
|
/** A hotel by its id - or by a name that fits one and only one of the hotels seen. */
|
|
184
284
|
const find = (ref) => {
|
|
185
285
|
const exact = hotels.get(ref.trim());
|
|
@@ -188,11 +288,10 @@ export const createOtalessHotels = (opts) => {
|
|
|
188
288
|
const key = nameKey(ref);
|
|
189
289
|
if (!key)
|
|
190
290
|
return undefined;
|
|
191
|
-
const
|
|
192
|
-
const same = all.filter((h) => nameKey(h.name) === key);
|
|
291
|
+
const same = [...hotels.values()].filter((h) => nameKey(h.name) === key);
|
|
193
292
|
if (same.length === 1)
|
|
194
293
|
return same[0];
|
|
195
|
-
const like =
|
|
294
|
+
const like = fitting(ref);
|
|
196
295
|
return like.length === 1 ? like[0] : undefined;
|
|
197
296
|
};
|
|
198
297
|
/**
|
|
@@ -201,30 +300,90 @@ export const createOtalessHotels = (opts) => {
|
|
|
201
300
|
* be read. Configured first, in the home page's order.
|
|
202
301
|
*/
|
|
203
302
|
const channelsFor = async (only) => {
|
|
204
|
-
if (only)
|
|
205
|
-
return [only];
|
|
206
303
|
let on = [];
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
304
|
+
const readSites = async () => {
|
|
305
|
+
try {
|
|
306
|
+
on = await client.sites();
|
|
307
|
+
}
|
|
308
|
+
catch (err) {
|
|
309
|
+
if (!(err instanceof OtalessError))
|
|
310
|
+
throw err;
|
|
311
|
+
}
|
|
312
|
+
noteGroups(on);
|
|
313
|
+
};
|
|
314
|
+
// ⚠️ ONLY A GROUP THIS MARKET KNOWS IS ASKED FOR BY NAME (C6): configured,
|
|
315
|
+
// on the backend's /site, or named in one of its answers. Anything else went
|
|
316
|
+
// to the backend as it came, as a channel code - and is no group here.
|
|
317
|
+
if (only) {
|
|
318
|
+
if (named.has(only) || seen.has(only))
|
|
319
|
+
return [only];
|
|
320
|
+
await readSites();
|
|
321
|
+
return on.includes(only) ? [only] : [];
|
|
213
322
|
}
|
|
323
|
+
await readSites();
|
|
214
324
|
const configured = (opts.groups ?? []).map((g) => g.code);
|
|
215
325
|
if (on.length === 0)
|
|
216
326
|
return configured;
|
|
217
|
-
noteGroups(on);
|
|
218
327
|
return [...configured.filter((c) => on.includes(c)), ...on.filter((c) => !named.has(c))];
|
|
219
328
|
};
|
|
220
|
-
|
|
221
|
-
|
|
329
|
+
/**
|
|
330
|
+
* The conversation a call is for - the trip it named, or its own - and its
|
|
331
|
+
* linked membership's token for this hotel's group, if any.
|
|
332
|
+
*/
|
|
333
|
+
const authOf = (h, who) => {
|
|
334
|
+
const key = who ? (who.tripOwner ?? who.sessionId) : undefined;
|
|
335
|
+
if (!key || !h.supplier)
|
|
336
|
+
return undefined;
|
|
337
|
+
const token = opts.memberAuth?.for?.(key, h.supplier);
|
|
338
|
+
return token ? { key, group: h.supplier, token } : undefined;
|
|
339
|
+
};
|
|
340
|
+
/**
|
|
341
|
+
* ⚠️ A MEMBERSHIP'S SESSION OVER (the backend's 4012) IS NOT "NO ROOMS": the
|
|
342
|
+
* link goes - the account page and the card say so - and the room is asked
|
|
343
|
+
* for again as anyone, at the standard rate.
|
|
344
|
+
*
|
|
345
|
+
* ⚠️ ONLY 4012 DOES THAT. A request held back by a limit (`OtalessBusy`, no
|
|
346
|
+
* backend code) is not a membership ended, and is not asked again without the
|
|
347
|
+
* token: the retry would be a second request over the same limit, and it would
|
|
348
|
+
* show a standard rate for a member.
|
|
349
|
+
*/
|
|
350
|
+
const asMember = async (auth, ask) => {
|
|
351
|
+
if (!auth)
|
|
352
|
+
return ask();
|
|
353
|
+
try {
|
|
354
|
+
return await ask(auth.token);
|
|
355
|
+
}
|
|
356
|
+
catch (err) {
|
|
357
|
+
if (err instanceof OtalessBusy ||
|
|
358
|
+
!(err instanceof OtalessError) ||
|
|
359
|
+
err.backendCode !== CHANNEL_SESSION_EXPIRED)
|
|
360
|
+
throw err;
|
|
361
|
+
opts.memberAuth?.expired?.(auth.key, auth.group);
|
|
362
|
+
return ask();
|
|
363
|
+
}
|
|
364
|
+
};
|
|
365
|
+
const roomsFor = async (h, stay, who) => {
|
|
366
|
+
const caller = callerOf(who);
|
|
367
|
+
const wire = await asMember(authOf(h, who), (token) => client.rooms({
|
|
222
368
|
unifiedHotelId: h.id,
|
|
223
369
|
checkIn: stay.checkIn,
|
|
224
370
|
checkOut: stay.checkOut,
|
|
225
|
-
});
|
|
226
|
-
|
|
371
|
+
}, caller, token));
|
|
372
|
+
const rooms = wire.flatMap((r) => toRoom(r, stay) ?? []);
|
|
373
|
+
for (const r of rooms) {
|
|
374
|
+
roomNames.delete(r.id);
|
|
375
|
+
roomNames.set(r.id, r.name);
|
|
376
|
+
}
|
|
377
|
+
while (roomNames.size > KEPT_ROOM_NAMES) {
|
|
378
|
+
const first = roomNames.keys().next().value;
|
|
379
|
+
if (first === undefined)
|
|
380
|
+
break;
|
|
381
|
+
roomNames.delete(first);
|
|
382
|
+
}
|
|
383
|
+
return rooms;
|
|
227
384
|
};
|
|
385
|
+
/** A room line its group gave no price for - the same sentence whether it sent none, refused, or sent it too late (C11). */
|
|
386
|
+
const noPriceWhy = (h, room, late = false) => `${groupOf(h.supplier ?? '').name} ${late ? 'gave no price in time' : 'sent no price'} for ${room ?? 'the room asked for'} at ${h.name} for those nights, so it is not priced in the trip.`;
|
|
228
387
|
const suppliers = () => [...(opts.groups ?? []).map((g) => g.code), ...[...seen].filter((c) => !named.has(c))].map((code) => {
|
|
229
388
|
const g = named.get(code);
|
|
230
389
|
return {
|
|
@@ -244,9 +403,14 @@ export const createOtalessHotels = (opts) => {
|
|
|
244
403
|
suppliers,
|
|
245
404
|
supplierOf: (hotelId) => hotels.get(hotelId)?.supplier ??
|
|
246
405
|
(hotelId.includes(':') ? hotelId.slice(0, hotelId.indexOf(':')) : undefined),
|
|
247
|
-
async searchHotels(q) {
|
|
248
|
-
const
|
|
406
|
+
async searchHotels(q, who) {
|
|
407
|
+
const words = text(q.city) ?? text(q.query);
|
|
408
|
+
// Cut at a few words' worth (C6): what is sent, kept and matched on.
|
|
409
|
+
const place = words ? text([...words].slice(0, MAX_PLACE).join('')) : undefined;
|
|
410
|
+
const caller = callerOf(who);
|
|
249
411
|
const channels = await channelsFor(q.filters?.supplier);
|
|
412
|
+
/** Groups not asked this time, and whose limit held them back (C6). */
|
|
413
|
+
const held = new Map();
|
|
250
414
|
// ⚠️ ONE REQUEST PER GROUP, SIDE BY SIDE (11-04): the backend answers for
|
|
251
415
|
// the first of `channelCodes` only. Each is waited for on its own (the
|
|
252
416
|
// client's limit); one that fails - HTTP 500, no answer, a refusal - or
|
|
@@ -257,16 +421,22 @@ export const createOtalessHotels = (opts) => {
|
|
|
257
421
|
channelCodes: [code],
|
|
258
422
|
...(place ? { destination: place } : {}),
|
|
259
423
|
...(q.stay
|
|
260
|
-
? {
|
|
424
|
+
? {
|
|
425
|
+
checkIn: q.stay.checkIn,
|
|
426
|
+
checkOut: q.stay.checkOut,
|
|
427
|
+
adultCount: q.stay.guests,
|
|
428
|
+
}
|
|
261
429
|
: {}),
|
|
262
430
|
...(q.filters?.bed ? { bed: q.filters.bed } : {}),
|
|
263
|
-
});
|
|
431
|
+
}, caller);
|
|
264
432
|
return { code, answer };
|
|
265
433
|
}
|
|
266
434
|
catch (err) {
|
|
435
|
+
if (err instanceof OtalessBusy)
|
|
436
|
+
held.set(code, err.by);
|
|
267
437
|
// ⚠️ ONE GROUP'S FAILURE, WHATEVER IT IS, IS THAT GROUP'S (0.55.3
|
|
268
438
|
// review): it did not answer; the others are still the list.
|
|
269
|
-
if (!(err instanceof OtalessError))
|
|
439
|
+
else if (!(err instanceof OtalessError))
|
|
270
440
|
console.error(`[otaless] ${code} search failed:`, err);
|
|
271
441
|
return { code, answer: undefined };
|
|
272
442
|
}
|
|
@@ -292,7 +462,7 @@ export const createOtalessHotels = (opts) => {
|
|
|
292
462
|
// not answer". Words that name no place this market knows narrow nothing:
|
|
293
463
|
// the backend's answer stands as it came (0.55.4 review).
|
|
294
464
|
const wanted = place
|
|
295
|
-
? wantedIn(place, each.flat(), (opts.groups ?? []).flatMap(
|
|
465
|
+
? wantedIn(place, each.flat(), (opts.groups ?? []).flatMap(groupNames))
|
|
296
466
|
: undefined;
|
|
297
467
|
// A group named by name (「香格里拉的酒店」) is that group's hotels alone -
|
|
298
468
|
// where no group filter was passed (0.55.5 review).
|
|
@@ -365,6 +535,15 @@ export const createOtalessHotels = (opts) => {
|
|
|
365
535
|
ignored.sort = true;
|
|
366
536
|
unapplied.push('No ratings are published here, so the list is not in rating order.');
|
|
367
537
|
}
|
|
538
|
+
// ⚠️ A GROUP HELD BACK BY A LIMIT OF OURS IS SAID AS THAT (C6): it is among
|
|
539
|
+
// `degraded` - left out, nothing to say about whether it has hotels here,
|
|
540
|
+
// no second look this turn - and this says why, in our words.
|
|
541
|
+
if (held.size) {
|
|
542
|
+
const groups = [...held.keys()].map((c) => groupOf(c).name);
|
|
543
|
+
const one = groups.length === 1;
|
|
544
|
+
const by = [...held.values()][0] ?? 'everyone';
|
|
545
|
+
unapplied.push(`${listAnd(groups)} ${one ? 'was' : 'were'} not asked for hotels this time: ${heldWhy(by)}. That is why ${one ? 'its' : 'their'} hotels are not in this list - it says nothing about whether ${one ? 'it has' : 'they have'} any here; the guest can ask again in a minute.`);
|
|
546
|
+
}
|
|
368
547
|
const count = (xs) => {
|
|
369
548
|
const m = new Map();
|
|
370
549
|
for (const x of xs)
|
|
@@ -390,7 +569,8 @@ export const createOtalessHotels = (opts) => {
|
|
|
390
569
|
})),
|
|
391
570
|
cities: count(passed.map((h) => h.city)).map(([name, n]) => {
|
|
392
571
|
const country = passed.find((h) => h.city === name)?.country;
|
|
393
|
-
|
|
572
|
+
const names = cityNames(name);
|
|
573
|
+
return { name, count: n, ...(country ? { country } : {}), ...(names ? { names } : {}) };
|
|
394
574
|
}),
|
|
395
575
|
},
|
|
396
576
|
refine: {
|
|
@@ -417,17 +597,14 @@ export const createOtalessHotels = (opts) => {
|
|
|
417
597
|
};
|
|
418
598
|
},
|
|
419
599
|
namesLike(ref) {
|
|
420
|
-
const
|
|
421
|
-
if (!key)
|
|
422
|
-
return [];
|
|
423
|
-
const like = [...hotels.values()].filter((h) => nameKey(h.name).includes(key));
|
|
600
|
+
const like = fitting(ref);
|
|
424
601
|
return like.length > 1
|
|
425
602
|
? like
|
|
426
603
|
.slice(0, 6)
|
|
427
604
|
.map((h) => ({ id: h.id, name: h.name, ...(h.city ? { city: h.city } : {}) }))
|
|
428
605
|
: [];
|
|
429
606
|
},
|
|
430
|
-
async getHotel(ref, stay) {
|
|
607
|
+
async getHotel(ref, stay, who) {
|
|
431
608
|
const h = find(ref);
|
|
432
609
|
if (!h)
|
|
433
610
|
return null;
|
|
@@ -435,7 +612,7 @@ export const createOtalessHotels = (opts) => {
|
|
|
435
612
|
return { hotel: h };
|
|
436
613
|
let rooms;
|
|
437
614
|
try {
|
|
438
|
-
rooms = await roomsFor(h, stay);
|
|
615
|
+
rooms = await roomsFor(h, stay, who);
|
|
439
616
|
}
|
|
440
617
|
catch (err) {
|
|
441
618
|
if (!(err instanceof OtalessError))
|
|
@@ -443,7 +620,10 @@ export const createOtalessHotels = (opts) => {
|
|
|
443
620
|
return {
|
|
444
621
|
hotel: h,
|
|
445
622
|
stay,
|
|
446
|
-
|
|
623
|
+
// ⚠️ OUR WORDS, NOT THE BACKEND'S (C10): what it said is on the log.
|
|
624
|
+
noRooms: err instanceof OtalessBusy
|
|
625
|
+
? `${h.name}'s rooms were not looked up this time: ${heldWhy(err.by)}. Nothing is wrong with the hotel or its rooms - the guest can ask again in a minute.`
|
|
626
|
+
: `${h.name}'s rooms could not be read just now.`,
|
|
447
627
|
noRoomsCode: 'unreachable',
|
|
448
628
|
};
|
|
449
629
|
}
|
|
@@ -471,40 +651,70 @@ export const createOtalessHotels = (opts) => {
|
|
|
471
651
|
rememberPreferences: async () => [],
|
|
472
652
|
extrasFor: async () => [],
|
|
473
653
|
policies: async () => [],
|
|
474
|
-
async quote(trip) {
|
|
475
|
-
const
|
|
476
|
-
const
|
|
477
|
-
|
|
478
|
-
|
|
654
|
+
async quote(trip, who) {
|
|
655
|
+
const caller = callerOf(who);
|
|
656
|
+
const outcomes = trip.lines.map(() => undefined);
|
|
657
|
+
/** The room lines still to price, by their place in the trip. */
|
|
658
|
+
const asked = [];
|
|
659
|
+
trip.lines.forEach((line, i) => {
|
|
479
660
|
if (line.kind !== 'room') {
|
|
480
|
-
|
|
481
|
-
title: line.extraId,
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
});
|
|
485
|
-
continue;
|
|
661
|
+
outcomes[i] = {
|
|
662
|
+
dropped: { title: line.extraId, why: 'No add-ons are sold here.', code: 'unavailable' },
|
|
663
|
+
};
|
|
664
|
+
return;
|
|
486
665
|
}
|
|
487
666
|
const h = find(line.hotelId);
|
|
488
667
|
if (!h) {
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
668
|
+
outcomes[i] = {
|
|
669
|
+
dropped: {
|
|
670
|
+
title: line.hotelId,
|
|
671
|
+
why: 'That hotel is not known here any more - search for it again.',
|
|
672
|
+
code: 'unavailable',
|
|
673
|
+
line: {
|
|
674
|
+
hotelId: line.hotelId,
|
|
675
|
+
stay: line.stay,
|
|
676
|
+
rooms: Math.max(1, Math.floor(line.rooms ?? 1)),
|
|
677
|
+
reason: 'gone',
|
|
678
|
+
},
|
|
679
|
+
},
|
|
680
|
+
};
|
|
681
|
+
return;
|
|
495
682
|
}
|
|
683
|
+
asked.push({ i, h, line });
|
|
684
|
+
});
|
|
685
|
+
/**
|
|
686
|
+
* The trip line a card draws in its place, with why it has no price (U2,
|
|
687
|
+
* 0.59.0) - `why` stays the assistant's sentence.
|
|
688
|
+
*/
|
|
689
|
+
const leftOut = (h, line, reason, roomName) => {
|
|
690
|
+
const g = groupOf(h.supplier ?? '');
|
|
691
|
+
return {
|
|
692
|
+
hotelId: h.id,
|
|
693
|
+
hotelName: h.name,
|
|
694
|
+
roomRef: line.roomId,
|
|
695
|
+
...(roomName ? { roomName } : {}),
|
|
696
|
+
stay: line.stay,
|
|
697
|
+
rooms: Math.max(1, Math.floor(line.rooms ?? 1)),
|
|
698
|
+
group: { name: g.name, ...(g.names ? { names: g.names } : {}) },
|
|
699
|
+
reason,
|
|
700
|
+
};
|
|
701
|
+
};
|
|
702
|
+
const priceLine = async (h, line) => {
|
|
496
703
|
const wanted = Math.max(1, Math.floor(line.rooms ?? 1));
|
|
704
|
+
const g = groupOf(h.supplier ?? '');
|
|
497
705
|
try {
|
|
498
|
-
const room = (await roomsFor(h, line.stay)).find((r) => r.id === line.roomId);
|
|
706
|
+
const room = (await roomsFor(h, line.stay, who)).find((r) => r.id === line.roomId);
|
|
499
707
|
if (!room) {
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
708
|
+
return {
|
|
709
|
+
dropped: {
|
|
710
|
+
title: h.name,
|
|
711
|
+
why: `${h.name} has no such room for ${line.stay.checkIn} to ${line.stay.checkOut} here.`,
|
|
712
|
+
code: 'unavailable',
|
|
713
|
+
line: leftOut(h, line, 'no-room'),
|
|
714
|
+
},
|
|
715
|
+
};
|
|
506
716
|
}
|
|
507
|
-
const q = await client.quote({
|
|
717
|
+
const q = await asMember(authOf(h, who), (token) => client.quote({
|
|
508
718
|
unifiedHotelId: h.id,
|
|
509
719
|
roomId: originalPart(room.id),
|
|
510
720
|
...(h.supplier ? { providerCode: h.supplier } : {}),
|
|
@@ -512,59 +722,105 @@ export const createOtalessHotels = (opts) => {
|
|
|
512
722
|
checkOut: line.stay.checkOut,
|
|
513
723
|
roomCount: wanted,
|
|
514
724
|
adultCount: line.stay.guests,
|
|
515
|
-
});
|
|
725
|
+
}, caller, token));
|
|
516
726
|
const currency = text(q.originalCurrency)?.toUpperCase();
|
|
517
727
|
const amount = num(q.originalAmount);
|
|
518
728
|
// ⚠️ AN ANSWER WITH NO PRICE IS NOT "DID NOT ANSWER": the dev backend
|
|
519
729
|
// quotes every room USD 0 (11-05, questions #46), and asking again
|
|
520
730
|
// gets the same - so it is said as the group's answer, with no "try
|
|
521
731
|
// again", and the room's own nightly rate is never made its total.
|
|
522
|
-
if (!currency || amount === undefined || amount <= 0)
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
732
|
+
if (!currency || amount === undefined || amount <= 0)
|
|
733
|
+
return {
|
|
734
|
+
dropped: {
|
|
735
|
+
title: h.name,
|
|
736
|
+
why: noPriceWhy(h, room.name),
|
|
737
|
+
code: 'unavailable',
|
|
738
|
+
line: leftOut(h, line, 'no-price', room.name),
|
|
739
|
+
},
|
|
740
|
+
};
|
|
530
741
|
const total = money(toMinor(amount, currency), currency);
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
742
|
+
return {
|
|
743
|
+
line: {
|
|
744
|
+
kind: 'room',
|
|
745
|
+
hotelId: h.id,
|
|
746
|
+
hotelName: h.name,
|
|
747
|
+
roomRef: room.id,
|
|
748
|
+
title: room.name,
|
|
749
|
+
// The bed in the group's words; breakfast as a code, which a card says
|
|
750
|
+
// in the guest's language (an English word here showed on a Chinese card).
|
|
751
|
+
...(room.beds ? { detail: room.beds } : {}),
|
|
752
|
+
...(room.breakfast ? { meal: { plan: 'breakfast' } } : {}),
|
|
753
|
+
stay: line.stay,
|
|
754
|
+
nights: room.nights,
|
|
755
|
+
quantity: wanted,
|
|
756
|
+
unit: room.nightly,
|
|
757
|
+
total,
|
|
758
|
+
terms: room.terms ?? '',
|
|
759
|
+
day: line.stay.checkIn,
|
|
760
|
+
},
|
|
761
|
+
};
|
|
549
762
|
}
|
|
550
763
|
catch (err) {
|
|
764
|
+
// Not sent - a limit of ours, said as that (C6).
|
|
765
|
+
if (err instanceof OtalessBusy)
|
|
766
|
+
return { held: g, by: err.by };
|
|
551
767
|
if (!(err instanceof OtalessError))
|
|
552
768
|
throw err;
|
|
553
769
|
// ⚠️ "DID NOT ANSWER" IS NOT "CANNOT BE HAD" (2026-11-03 review, C5).
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
dropped.push({
|
|
770
|
+
if (err.backendCode === undefined)
|
|
771
|
+
return { silent: g };
|
|
772
|
+
// A refusal, in our words (C10): the backend's are on the log.
|
|
773
|
+
return {
|
|
774
|
+
dropped: {
|
|
560
775
|
title: h.name,
|
|
561
|
-
why:
|
|
776
|
+
why: noPriceWhy(h, roomNames.get(line.roomId)),
|
|
562
777
|
code: 'unavailable',
|
|
563
|
-
|
|
564
|
-
|
|
778
|
+
// Their refusal is said as no price, as `why` says it (C10).
|
|
779
|
+
line: leftOut(h, line, 'no-price', roomNames.get(line.roomId)),
|
|
780
|
+
},
|
|
781
|
+
};
|
|
565
782
|
}
|
|
783
|
+
};
|
|
784
|
+
// ⚠️ SIDE BY SIDE, A FEW AT A TIME, AND WITHIN ONE TIME (C11). A line not
|
|
785
|
+
// priced by then is the group's that gave no price in time - as the card
|
|
786
|
+
// says a line with no price (U2), not as a fault of the whole trip.
|
|
787
|
+
await within(asked.map(({ i, h, line }) => async () => {
|
|
788
|
+
outcomes[i] = await priceLine(h, line);
|
|
789
|
+
}), opts.quoteParallel ?? QUOTE_PARALLEL, opts.quoteDeadlineMs ?? QUOTE_DEADLINE_MS);
|
|
790
|
+
for (const { i, h, line } of asked)
|
|
791
|
+
outcomes[i] ??= {
|
|
792
|
+
dropped: {
|
|
793
|
+
title: h.name,
|
|
794
|
+
why: noPriceWhy(h, roomNames.get(line.roomId), true),
|
|
795
|
+
code: 'unavailable',
|
|
796
|
+
// No price in time is no price (robin, C11).
|
|
797
|
+
line: leftOut(h, line, 'no-price', roomNames.get(line.roomId)),
|
|
798
|
+
},
|
|
799
|
+
};
|
|
800
|
+
const lines = [];
|
|
801
|
+
const dropped = [];
|
|
802
|
+
const silent = new Map();
|
|
803
|
+
const held = new Map();
|
|
804
|
+
for (const o of outcomes) {
|
|
805
|
+
if (!o)
|
|
806
|
+
continue;
|
|
807
|
+
if ('line' in o)
|
|
808
|
+
lines.push(o.line);
|
|
809
|
+
else if ('dropped' in o)
|
|
810
|
+
dropped.push(o.dropped);
|
|
811
|
+
else if ('silent' in o)
|
|
812
|
+
silent.set(o.silent.supplier, o.silent);
|
|
813
|
+
else if (!held.has(o.held.supplier))
|
|
814
|
+
held.set(o.held.supplier, { g: o.held, by: o.by });
|
|
566
815
|
}
|
|
567
816
|
dropped.push(...[...silent.values()].map(notPricedForNoAnswer));
|
|
817
|
+
// Held back by a limit of ours: the group's part is not priced, and the
|
|
818
|
+
// guest can ask again (`unreachable` - the answer adds when).
|
|
819
|
+
dropped.push(...[...held.values()].map(({ g, by }) => ({
|
|
820
|
+
title: g.name,
|
|
821
|
+
why: `${g.name} was not asked to price its part of this trip: ${heldWhy(by)}. That part is not priced here - this does not mean it cannot be had.`,
|
|
822
|
+
code: 'unreachable',
|
|
823
|
+
})));
|
|
568
824
|
const currency = lines[0]?.total.currency ?? EMPTY_CURRENCY;
|
|
569
825
|
if (lines.some((l) => l.total.currency !== currency)) {
|
|
570
826
|
throw refusal('mixed-currency', `These hotels charge in ${[...new Set(lines.map((l) => l.total.currency))].join(' and ')}; a trip is priced one currency at a time.`);
|