@curless/hotel-storefront 0.58.1 → 0.59.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.
Files changed (83) hide show
  1. package/dist/account/fake-mall.d.ts +19 -0
  2. package/dist/account/fake-mall.d.ts.map +1 -1
  3. package/dist/account/fake-mall.js +81 -10
  4. package/dist/account/fake-mall.js.map +1 -1
  5. package/dist/account/index.d.ts +75 -3
  6. package/dist/account/index.d.ts.map +1 -1
  7. package/dist/account/index.js +769 -33
  8. package/dist/account/index.js.map +1 -1
  9. package/dist/account/mall.d.ts +3 -1
  10. package/dist/account/mall.d.ts.map +1 -1
  11. package/dist/account/mall.js +17 -2
  12. package/dist/account/mall.js.map +1 -1
  13. package/dist/account/ota-member.d.ts +72 -0
  14. package/dist/account/ota-member.d.ts.map +1 -0
  15. package/dist/account/ota-member.js +127 -0
  16. package/dist/account/ota-member.js.map +1 -0
  17. package/dist/account/pages.d.ts +99 -4
  18. package/dist/account/pages.d.ts.map +1 -1
  19. package/dist/account/pages.js +221 -16
  20. package/dist/account/pages.js.map +1 -1
  21. package/dist/account/requests.d.ts +13 -1
  22. package/dist/account/requests.d.ts.map +1 -1
  23. package/dist/account/requests.js +2 -1
  24. package/dist/account/requests.js.map +1 -1
  25. package/dist/account/store.d.ts +8 -0
  26. package/dist/account/store.d.ts.map +1 -1
  27. package/dist/account/store.js.map +1 -1
  28. package/dist/aggregate/places.d.ts +10 -0
  29. package/dist/aggregate/places.d.ts.map +1 -1
  30. package/dist/aggregate/places.js +21 -0
  31. package/dist/aggregate/places.js.map +1 -1
  32. package/dist/card.generated.d.ts +1 -1
  33. package/dist/card.generated.js +2 -2
  34. package/dist/card.generated.js.map +1 -1
  35. package/dist/dates.d.ts +33 -0
  36. package/dist/dates.d.ts.map +1 -1
  37. package/dist/dates.js +46 -0
  38. package/dist/dates.js.map +1 -1
  39. package/dist/otaless/backend.d.ts +28 -0
  40. package/dist/otaless/backend.d.ts.map +1 -1
  41. package/dist/otaless/backend.js +330 -84
  42. package/dist/otaless/backend.js.map +1 -1
  43. package/dist/otaless/client.d.ts +46 -4
  44. package/dist/otaless/client.d.ts.map +1 -1
  45. package/dist/otaless/client.js +138 -35
  46. package/dist/otaless/client.js.map +1 -1
  47. package/dist/otaless/limits.d.ts +58 -0
  48. package/dist/otaless/limits.d.ts.map +1 -0
  49. package/dist/otaless/limits.js +132 -0
  50. package/dist/otaless/limits.js.map +1 -0
  51. package/dist/otaless/make.d.ts.map +1 -1
  52. package/dist/otaless/make.js +14 -1
  53. package/dist/otaless/make.js.map +1 -1
  54. package/dist/present.d.ts +12 -1
  55. package/dist/present.d.ts.map +1 -1
  56. package/dist/present.js +27 -1
  57. package/dist/present.js.map +1 -1
  58. package/dist/server.d.ts +2 -2
  59. package/dist/server.d.ts.map +1 -1
  60. package/dist/server.js +54 -35
  61. package/dist/server.js.map +1 -1
  62. package/dist/sessions.d.ts +23 -4
  63. package/dist/sessions.d.ts.map +1 -1
  64. package/dist/sessions.js +57 -7
  65. package/dist/sessions.js.map +1 -1
  66. package/dist/supplier.d.ts +6 -0
  67. package/dist/supplier.d.ts.map +1 -1
  68. package/dist/supplier.js.map +1 -1
  69. package/dist/surface.d.ts +2 -0
  70. package/dist/surface.d.ts.map +1 -1
  71. package/dist/surface.js +23 -3
  72. package/dist/surface.js.map +1 -1
  73. package/dist/tools.d.ts +2 -2
  74. package/dist/tools.d.ts.map +1 -1
  75. package/dist/tools.js +196 -69
  76. package/dist/tools.js.map +1 -1
  77. package/dist/trip-ids.d.ts +35 -4
  78. package/dist/trip-ids.d.ts.map +1 -1
  79. package/dist/trip-ids.js +87 -19
  80. package/dist/trip-ids.js.map +1 -1
  81. package/dist/types.d.ts +35 -6
  82. package/dist/types.d.ts.map +1 -1
  83. package/package.json +1 -1
@@ -1,9 +1,11 @@
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';
8
+ import { CHANNEL_SESSION_EXPIRED, OtalessBusy, OtalessError, } from './client.js';
7
9
  import { codeOfCountry, groupsIn, 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,如果没数据就不显示」).
@@ -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) } : {}),
@@ -201,30 +287,90 @@ export const createOtalessHotels = (opts) => {
201
287
  * be read. Configured first, in the home page's order.
202
288
  */
203
289
  const channelsFor = async (only) => {
204
- if (only)
205
- return [only];
206
290
  let on = [];
207
- try {
208
- on = await client.sites();
209
- }
210
- catch (err) {
211
- if (!(err instanceof OtalessError))
212
- throw err;
291
+ const readSites = async () => {
292
+ try {
293
+ on = await client.sites();
294
+ }
295
+ catch (err) {
296
+ if (!(err instanceof OtalessError))
297
+ throw err;
298
+ }
299
+ noteGroups(on);
300
+ };
301
+ // ⚠️ ONLY A GROUP THIS MARKET KNOWS IS ASKED FOR BY NAME (C6): configured,
302
+ // on the backend's /site, or named in one of its answers. Anything else went
303
+ // to the backend as it came, as a channel code - and is no group here.
304
+ if (only) {
305
+ if (named.has(only) || seen.has(only))
306
+ return [only];
307
+ await readSites();
308
+ return on.includes(only) ? [only] : [];
213
309
  }
310
+ await readSites();
214
311
  const configured = (opts.groups ?? []).map((g) => g.code);
215
312
  if (on.length === 0)
216
313
  return configured;
217
- noteGroups(on);
218
314
  return [...configured.filter((c) => on.includes(c)), ...on.filter((c) => !named.has(c))];
219
315
  };
220
- const roomsFor = async (h, stay) => {
221
- const wire = await client.rooms({
316
+ /**
317
+ * The conversation a call is for - the trip it named, or its own - and its
318
+ * linked membership's token for this hotel's group, if any.
319
+ */
320
+ const authOf = (h, who) => {
321
+ const key = who ? (who.tripOwner ?? who.sessionId) : undefined;
322
+ if (!key || !h.supplier)
323
+ return undefined;
324
+ const token = opts.memberAuth?.for?.(key, h.supplier);
325
+ return token ? { key, group: h.supplier, token } : undefined;
326
+ };
327
+ /**
328
+ * ⚠️ A MEMBERSHIP'S SESSION OVER (the backend's 4012) IS NOT "NO ROOMS": the
329
+ * link goes - the account page and the card say so - and the room is asked
330
+ * for again as anyone, at the standard rate.
331
+ *
332
+ * ⚠️ ONLY 4012 DOES THAT. A request held back by a limit (`OtalessBusy`, no
333
+ * backend code) is not a membership ended, and is not asked again without the
334
+ * token: the retry would be a second request over the same limit, and it would
335
+ * show a standard rate for a member.
336
+ */
337
+ const asMember = async (auth, ask) => {
338
+ if (!auth)
339
+ return ask();
340
+ try {
341
+ return await ask(auth.token);
342
+ }
343
+ catch (err) {
344
+ if (err instanceof OtalessBusy ||
345
+ !(err instanceof OtalessError) ||
346
+ err.backendCode !== CHANNEL_SESSION_EXPIRED)
347
+ throw err;
348
+ opts.memberAuth?.expired?.(auth.key, auth.group);
349
+ return ask();
350
+ }
351
+ };
352
+ const roomsFor = async (h, stay, who) => {
353
+ const caller = callerOf(who);
354
+ const wire = await asMember(authOf(h, who), (token) => client.rooms({
222
355
  unifiedHotelId: h.id,
223
356
  checkIn: stay.checkIn,
224
357
  checkOut: stay.checkOut,
225
- });
226
- return wire.flatMap((r) => toRoom(r, stay) ?? []);
358
+ }, caller, token));
359
+ const rooms = wire.flatMap((r) => toRoom(r, stay) ?? []);
360
+ for (const r of rooms) {
361
+ roomNames.delete(r.id);
362
+ roomNames.set(r.id, r.name);
363
+ }
364
+ while (roomNames.size > KEPT_ROOM_NAMES) {
365
+ const first = roomNames.keys().next().value;
366
+ if (first === undefined)
367
+ break;
368
+ roomNames.delete(first);
369
+ }
370
+ return rooms;
227
371
  };
372
+ /** A room line its group gave no price for - the same sentence whether it sent none, refused, or sent it too late (C11). */
373
+ 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
374
  const suppliers = () => [...(opts.groups ?? []).map((g) => g.code), ...[...seen].filter((c) => !named.has(c))].map((code) => {
229
375
  const g = named.get(code);
230
376
  return {
@@ -244,9 +390,14 @@ export const createOtalessHotels = (opts) => {
244
390
  suppliers,
245
391
  supplierOf: (hotelId) => hotels.get(hotelId)?.supplier ??
246
392
  (hotelId.includes(':') ? hotelId.slice(0, hotelId.indexOf(':')) : undefined),
247
- async searchHotels(q) {
248
- const place = text(q.city) ?? text(q.query);
393
+ async searchHotels(q, who) {
394
+ const words = text(q.city) ?? text(q.query);
395
+ // Cut at a few words' worth (C6): what is sent, kept and matched on.
396
+ const place = words ? text([...words].slice(0, MAX_PLACE).join('')) : undefined;
397
+ const caller = callerOf(who);
249
398
  const channels = await channelsFor(q.filters?.supplier);
399
+ /** Groups not asked this time, and whose limit held them back (C6). */
400
+ const held = new Map();
250
401
  // ⚠️ ONE REQUEST PER GROUP, SIDE BY SIDE (11-04): the backend answers for
251
402
  // the first of `channelCodes` only. Each is waited for on its own (the
252
403
  // client's limit); one that fails - HTTP 500, no answer, a refusal - or
@@ -257,16 +408,22 @@ export const createOtalessHotels = (opts) => {
257
408
  channelCodes: [code],
258
409
  ...(place ? { destination: place } : {}),
259
410
  ...(q.stay
260
- ? { checkIn: q.stay.checkIn, checkOut: q.stay.checkOut, adultCount: q.stay.guests }
411
+ ? {
412
+ checkIn: q.stay.checkIn,
413
+ checkOut: q.stay.checkOut,
414
+ adultCount: q.stay.guests,
415
+ }
261
416
  : {}),
262
417
  ...(q.filters?.bed ? { bed: q.filters.bed } : {}),
263
- });
418
+ }, caller);
264
419
  return { code, answer };
265
420
  }
266
421
  catch (err) {
422
+ if (err instanceof OtalessBusy)
423
+ held.set(code, err.by);
267
424
  // ⚠️ ONE GROUP'S FAILURE, WHATEVER IT IS, IS THAT GROUP'S (0.55.3
268
425
  // review): it did not answer; the others are still the list.
269
- if (!(err instanceof OtalessError))
426
+ else if (!(err instanceof OtalessError))
270
427
  console.error(`[otaless] ${code} search failed:`, err);
271
428
  return { code, answer: undefined };
272
429
  }
@@ -365,6 +522,15 @@ export const createOtalessHotels = (opts) => {
365
522
  ignored.sort = true;
366
523
  unapplied.push('No ratings are published here, so the list is not in rating order.');
367
524
  }
525
+ // ⚠️ A GROUP HELD BACK BY A LIMIT OF OURS IS SAID AS THAT (C6): it is among
526
+ // `degraded` - left out, nothing to say about whether it has hotels here,
527
+ // no second look this turn - and this says why, in our words.
528
+ if (held.size) {
529
+ const groups = [...held.keys()].map((c) => groupOf(c).name);
530
+ const one = groups.length === 1;
531
+ const by = [...held.values()][0] ?? 'everyone';
532
+ 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.`);
533
+ }
368
534
  const count = (xs) => {
369
535
  const m = new Map();
370
536
  for (const x of xs)
@@ -390,7 +556,8 @@ export const createOtalessHotels = (opts) => {
390
556
  })),
391
557
  cities: count(passed.map((h) => h.city)).map(([name, n]) => {
392
558
  const country = passed.find((h) => h.city === name)?.country;
393
- return { name, count: n, ...(country ? { country } : {}) };
559
+ const names = cityNames(name);
560
+ return { name, count: n, ...(country ? { country } : {}), ...(names ? { names } : {}) };
394
561
  }),
395
562
  },
396
563
  refine: {
@@ -427,7 +594,7 @@ export const createOtalessHotels = (opts) => {
427
594
  .map((h) => ({ id: h.id, name: h.name, ...(h.city ? { city: h.city } : {}) }))
428
595
  : [];
429
596
  },
430
- async getHotel(ref, stay) {
597
+ async getHotel(ref, stay, who) {
431
598
  const h = find(ref);
432
599
  if (!h)
433
600
  return null;
@@ -435,7 +602,7 @@ export const createOtalessHotels = (opts) => {
435
602
  return { hotel: h };
436
603
  let rooms;
437
604
  try {
438
- rooms = await roomsFor(h, stay);
605
+ rooms = await roomsFor(h, stay, who);
439
606
  }
440
607
  catch (err) {
441
608
  if (!(err instanceof OtalessError))
@@ -443,7 +610,10 @@ export const createOtalessHotels = (opts) => {
443
610
  return {
444
611
  hotel: h,
445
612
  stay,
446
- noRooms: `${h.name}'s rooms could not be read just now (${err.message}).`,
613
+ // ⚠️ OUR WORDS, NOT THE BACKEND'S (C10): what it said is on the log.
614
+ noRooms: err instanceof OtalessBusy
615
+ ? `${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.`
616
+ : `${h.name}'s rooms could not be read just now.`,
447
617
  noRoomsCode: 'unreachable',
448
618
  };
449
619
  }
@@ -471,40 +641,70 @@ export const createOtalessHotels = (opts) => {
471
641
  rememberPreferences: async () => [],
472
642
  extrasFor: async () => [],
473
643
  policies: async () => [],
474
- async quote(trip) {
475
- const lines = [];
476
- const dropped = [];
477
- const silent = new Map();
478
- for (const line of trip.lines) {
644
+ async quote(trip, who) {
645
+ const caller = callerOf(who);
646
+ const outcomes = trip.lines.map(() => undefined);
647
+ /** The room lines still to price, by their place in the trip. */
648
+ const asked = [];
649
+ trip.lines.forEach((line, i) => {
479
650
  if (line.kind !== 'room') {
480
- dropped.push({
481
- title: line.extraId,
482
- why: 'No add-ons are sold here.',
483
- code: 'unavailable',
484
- });
485
- continue;
651
+ outcomes[i] = {
652
+ dropped: { title: line.extraId, why: 'No add-ons are sold here.', code: 'unavailable' },
653
+ };
654
+ return;
486
655
  }
487
656
  const h = find(line.hotelId);
488
657
  if (!h) {
489
- dropped.push({
490
- title: line.hotelId,
491
- why: 'That hotel is not known here any more - search for it again.',
492
- code: 'unavailable',
493
- });
494
- continue;
658
+ outcomes[i] = {
659
+ dropped: {
660
+ title: line.hotelId,
661
+ why: 'That hotel is not known here any more - search for it again.',
662
+ code: 'unavailable',
663
+ line: {
664
+ hotelId: line.hotelId,
665
+ stay: line.stay,
666
+ rooms: Math.max(1, Math.floor(line.rooms ?? 1)),
667
+ reason: 'gone',
668
+ },
669
+ },
670
+ };
671
+ return;
495
672
  }
673
+ asked.push({ i, h, line });
674
+ });
675
+ /**
676
+ * The trip line a card draws in its place, with why it has no price (U2,
677
+ * 0.59.0) - `why` stays the assistant's sentence.
678
+ */
679
+ const leftOut = (h, line, reason, roomName) => {
680
+ const g = groupOf(h.supplier ?? '');
681
+ return {
682
+ hotelId: h.id,
683
+ hotelName: h.name,
684
+ roomRef: line.roomId,
685
+ ...(roomName ? { roomName } : {}),
686
+ stay: line.stay,
687
+ rooms: Math.max(1, Math.floor(line.rooms ?? 1)),
688
+ group: { name: g.name, ...(g.names ? { names: g.names } : {}) },
689
+ reason,
690
+ };
691
+ };
692
+ const priceLine = async (h, line) => {
496
693
  const wanted = Math.max(1, Math.floor(line.rooms ?? 1));
694
+ const g = groupOf(h.supplier ?? '');
497
695
  try {
498
- const room = (await roomsFor(h, line.stay)).find((r) => r.id === line.roomId);
696
+ const room = (await roomsFor(h, line.stay, who)).find((r) => r.id === line.roomId);
499
697
  if (!room) {
500
- dropped.push({
501
- title: h.name,
502
- why: `${h.name} has no such room for ${line.stay.checkIn} to ${line.stay.checkOut} here.`,
503
- code: 'unavailable',
504
- });
505
- continue;
698
+ return {
699
+ dropped: {
700
+ title: h.name,
701
+ why: `${h.name} has no such room for ${line.stay.checkIn} to ${line.stay.checkOut} here.`,
702
+ code: 'unavailable',
703
+ line: leftOut(h, line, 'no-room'),
704
+ },
705
+ };
506
706
  }
507
- const q = await client.quote({
707
+ const q = await asMember(authOf(h, who), (token) => client.quote({
508
708
  unifiedHotelId: h.id,
509
709
  roomId: originalPart(room.id),
510
710
  ...(h.supplier ? { providerCode: h.supplier } : {}),
@@ -512,59 +712,105 @@ export const createOtalessHotels = (opts) => {
512
712
  checkOut: line.stay.checkOut,
513
713
  roomCount: wanted,
514
714
  adultCount: line.stay.guests,
515
- });
715
+ }, caller, token));
516
716
  const currency = text(q.originalCurrency)?.toUpperCase();
517
717
  const amount = num(q.originalAmount);
518
718
  // ⚠️ AN ANSWER WITH NO PRICE IS NOT "DID NOT ANSWER": the dev backend
519
719
  // quotes every room USD 0 (11-05, questions #46), and asking again
520
720
  // gets the same - so it is said as the group's answer, with no "try
521
721
  // again", and the room's own nightly rate is never made its total.
522
- if (!currency || amount === undefined || amount <= 0) {
523
- dropped.push({
524
- title: h.name,
525
- why: `${groupOf(h.supplier ?? '').name} sent no price for ${room.name} at ${h.name} for those nights, so it is not priced in the trip.`,
526
- code: 'unavailable',
527
- });
528
- continue;
529
- }
722
+ if (!currency || amount === undefined || amount <= 0)
723
+ return {
724
+ dropped: {
725
+ title: h.name,
726
+ why: noPriceWhy(h, room.name),
727
+ code: 'unavailable',
728
+ line: leftOut(h, line, 'no-price', room.name),
729
+ },
730
+ };
530
731
  const total = money(toMinor(amount, currency), currency);
531
- lines.push({
532
- kind: 'room',
533
- hotelId: h.id,
534
- hotelName: h.name,
535
- roomRef: room.id,
536
- title: room.name,
537
- // The bed in the group's words; breakfast as a code, which a card says
538
- // in the guest's language (an English word here showed on a Chinese card).
539
- ...(room.beds ? { detail: room.beds } : {}),
540
- ...(room.breakfast ? { meal: { plan: 'breakfast' } } : {}),
541
- stay: line.stay,
542
- nights: room.nights,
543
- quantity: wanted,
544
- unit: room.nightly,
545
- total,
546
- terms: room.terms ?? '',
547
- day: line.stay.checkIn,
548
- });
732
+ return {
733
+ line: {
734
+ kind: 'room',
735
+ hotelId: h.id,
736
+ hotelName: h.name,
737
+ roomRef: room.id,
738
+ title: room.name,
739
+ // The bed in the group's words; breakfast as a code, which a card says
740
+ // in the guest's language (an English word here showed on a Chinese card).
741
+ ...(room.beds ? { detail: room.beds } : {}),
742
+ ...(room.breakfast ? { meal: { plan: 'breakfast' } } : {}),
743
+ stay: line.stay,
744
+ nights: room.nights,
745
+ quantity: wanted,
746
+ unit: room.nightly,
747
+ total,
748
+ terms: room.terms ?? '',
749
+ day: line.stay.checkIn,
750
+ },
751
+ };
549
752
  }
550
753
  catch (err) {
754
+ // Not sent - a limit of ours, said as that (C6).
755
+ if (err instanceof OtalessBusy)
756
+ return { held: g, by: err.by };
551
757
  if (!(err instanceof OtalessError))
552
758
  throw err;
553
759
  // ⚠️ "DID NOT ANSWER" IS NOT "CANNOT BE HAD" (2026-11-03 review, C5).
554
- const g = groupOf(h.supplier ?? '');
555
- if (err.backendCode === undefined) {
556
- silent.set(g.supplier, g);
557
- }
558
- else {
559
- dropped.push({
760
+ if (err.backendCode === undefined)
761
+ return { silent: g };
762
+ // A refusal, in our words (C10): the backend's are on the log.
763
+ return {
764
+ dropped: {
560
765
  title: h.name,
561
- why: `${g.name} could not price ${h.name} for those nights: ${err.message}.`,
766
+ why: noPriceWhy(h, roomNames.get(line.roomId)),
562
767
  code: 'unavailable',
563
- });
564
- }
768
+ // Their refusal is said as no price, as `why` says it (C10).
769
+ line: leftOut(h, line, 'no-price', roomNames.get(line.roomId)),
770
+ },
771
+ };
565
772
  }
773
+ };
774
+ // ⚠️ SIDE BY SIDE, A FEW AT A TIME, AND WITHIN ONE TIME (C11). A line not
775
+ // priced by then is the group's that gave no price in time - as the card
776
+ // says a line with no price (U2), not as a fault of the whole trip.
777
+ await within(asked.map(({ i, h, line }) => async () => {
778
+ outcomes[i] = await priceLine(h, line);
779
+ }), opts.quoteParallel ?? QUOTE_PARALLEL, opts.quoteDeadlineMs ?? QUOTE_DEADLINE_MS);
780
+ for (const { i, h, line } of asked)
781
+ outcomes[i] ??= {
782
+ dropped: {
783
+ title: h.name,
784
+ why: noPriceWhy(h, roomNames.get(line.roomId), true),
785
+ code: 'unavailable',
786
+ // No price in time is no price (robin, C11).
787
+ line: leftOut(h, line, 'no-price', roomNames.get(line.roomId)),
788
+ },
789
+ };
790
+ const lines = [];
791
+ const dropped = [];
792
+ const silent = new Map();
793
+ const held = new Map();
794
+ for (const o of outcomes) {
795
+ if (!o)
796
+ continue;
797
+ if ('line' in o)
798
+ lines.push(o.line);
799
+ else if ('dropped' in o)
800
+ dropped.push(o.dropped);
801
+ else if ('silent' in o)
802
+ silent.set(o.silent.supplier, o.silent);
803
+ else if (!held.has(o.held.supplier))
804
+ held.set(o.held.supplier, { g: o.held, by: o.by });
566
805
  }
567
806
  dropped.push(...[...silent.values()].map(notPricedForNoAnswer));
807
+ // Held back by a limit of ours: the group's part is not priced, and the
808
+ // guest can ask again (`unreachable` - the answer adds when).
809
+ dropped.push(...[...held.values()].map(({ g, by }) => ({
810
+ title: g.name,
811
+ 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.`,
812
+ code: 'unreachable',
813
+ })));
568
814
  const currency = lines[0]?.total.currency ?? EMPTY_CURRENCY;
569
815
  if (lines.some((l) => l.total.currency !== currency)) {
570
816
  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.`);