@curless/hotel-storefront 0.71.5 → 0.72.1

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.
@@ -4,7 +4,7 @@ import { guestTooLong } from '../backend.js';
4
4
  import { nights as nightsOf } from '../dates.js';
5
5
  import { movedSince } from '../huazhu/backend.js';
6
6
  import { decimalsOf, minorFactor, money, toMinor } from '../money.js';
7
- import { CHANNEL_SESSION_EXPIRED, NOT_SIGNED_IN, OtalessBusy, OtalessError, REPEAT_SUBMIT, SESSION_ID, forTheLog, } from './client.js';
7
+ import { CHANNEL_SESSION_EXPIRED, NOT_SIGNED_IN, OtalessBusy, OtalessError, REPEAT_SUBMIT, SESSION_ID, forTheLog, isBookingTerms, } from './client.js';
8
8
  // Booking on the Otaless hotel backend: items 8-16 of its document of
9
9
  // 2026-11-10. Since 2026-11-11 the order is 8 `booking/create` - the backend's
10
10
  // own answer to questions #56: 「booking/create 就行,checkout 所有的 api 不需要」
@@ -17,6 +17,10 @@ import { CHANNEL_SESSION_EXPIRED, NOT_SIGNED_IN, OtalessBusy, OtalessError, REPE
17
17
  // group sent them with the room, word for word - are shown before anything
18
18
  // is ordered, and 8 is called only once the guest agreed on the card's own
19
19
  // button or the one-time page (`acceptTerms`), never on the model's word.
20
+ // A group whose `/site` row says `termsRequired` (the 11-16 document, 0.72.1)
21
+ // is asked for its own terms by 8 itself - `termsRequired: true`, which
22
+ // answers them and orders nothing - and those are what the guest agrees to;
23
+ // only then is 8 sent again, with `termsRequired: false`, to order it.
20
24
  // Terms the group answers the order with that are not the ones agreed hold
21
25
  // the order's payment page back until the guest agrees to them too; not
22
26
  // agreed, or not in `TERMS_MS`, the order is cancelled (9).
@@ -191,6 +195,8 @@ const CHECKED_PER_LOOK = 5;
191
195
  export const DEFAULT_CHECKOUT_HOSTS = ['pay.discoverasr.com'];
192
196
  /** How long a refund's preview can be sent back (总线程's review of 0.63.0, B). */
193
197
  export const REFUND_PREVIEW_MS = 10 * 60_000;
198
+ /** How long the 7 before the group's terms stands for the 7 before the order, on a 10014 (`pricedRecently`). */
199
+ export const PRICED_IN_MS = 30_000;
194
200
  const refusal = (code, message) => Object.assign(new Error(message), { code });
195
201
  const signInRefusal = (code, message, groups) => Object.assign(new Error(message), { code, groups: [...groups] });
196
202
  const num = (v) => {
@@ -635,6 +641,18 @@ export const createOtalessBookings = (deps) => {
635
641
  group,
636
642
  };
637
643
  };
644
+ /**
645
+ * Whether `group` asks for its own terms before it is booked - its `/site` row's
646
+ * `termsRequired` (0.72.1; client.ts keeps it by group). `undefined`: not said.
647
+ */
648
+ const groupTermsOf = async (group) => {
649
+ try {
650
+ return await client.termsRequired(group);
651
+ }
652
+ catch {
653
+ return undefined;
654
+ }
655
+ };
638
656
  const signInFirst = (groups) => signInRefusal('sign-in', `Nothing was booked: booking at ${groups.map((g) => deps.groupOf(g).name).join(' and ')} needs the guest signed in there through their ${deps.brand} account - ask them to sign in first.`, groups);
639
657
  /**
640
658
  * One of this guest's orders, by its id or the code the guest quotes, with
@@ -888,7 +906,6 @@ export const createOtalessBookings = (deps) => {
888
906
  const limited = (a, name) => failedStay(a, `Not sent to ${name}: too many requests just now - ask again in a minute.`, 'limited');
889
907
  const recordOf = (a, pairs, id, code, status) => ({
890
908
  ...(a.noTerms ? { noTerms: true } : {}),
891
- ...(a.autoAccepted ? { stepUnsent: a.autoAccepted, autoAccepted: true } : {}),
892
909
  id,
893
910
  code,
894
911
  group: a.group,
@@ -957,8 +974,12 @@ export const createOtalessBookings = (deps) => {
957
974
  const g = deps.groupOf(code);
958
975
  return { groupName: g.name, ...(g.names ? { groupNames: g.names } : {}) };
959
976
  };
960
- /** The terms of one stay, for the guest to agree to before it is ordered. */
961
- const termsBefore = (a) => remember({
977
+ /**
978
+ * The terms of one stay, for the guest to agree to before it is ordered. `askGroup`: its
979
+ * group's `/site` did not say whether it asks for terms of its own - agreed, 8 is sent with
980
+ * `termsRequired: true` (0.72.1).
981
+ */
982
+ const termsBefore = (a, askGroup = false) => remember({
962
983
  ref: randomBytes(18).toString('base64url'),
963
984
  group: a.group,
964
985
  ...groupWords(a.group),
@@ -975,7 +996,11 @@ export const createOtalessBookings = (deps) => {
975
996
  until: iso(now() + TERMS_MS),
976
997
  owner: a.acct.owner,
977
998
  key: a.acct.key,
978
- ask: { roomId: a.roomId, guest: a.guest },
999
+ ask: {
1000
+ roomId: a.roomId,
1001
+ guest: a.guest,
1002
+ ...(askGroup ? { groupTerms: 'ask' } : {}),
1003
+ },
979
1004
  });
980
1005
  /** Where what a group asks to agree to or confirm is not what the guest was shown - or nothing. */
981
1006
  const stepOff = (asked, a, pairs) => asked.amountUnread ||
@@ -994,12 +1019,12 @@ export const createOtalessBookings = (deps) => {
994
1019
  * and sent once more with the token. Without both - or asked again after the
995
1020
  * guest did it - nothing is booked, and the log says which it was.
996
1021
  */
997
- const groupAsked = (a, step, data, pairs, msg) => {
1022
+ const groupAsked = (a, step, data, pairs) => {
998
1023
  const g = deps.groupOf(a.group);
999
1024
  const what = `${step}_required`;
1000
1025
  const code = (step === 'terms' ? 'group-terms' : 'group-confirm');
1001
1026
  const asked = groupStepOf(step, data);
1002
- if (asked && !a.groupStep) {
1027
+ if (asked && !a.groupStep && a.groupTerms !== 'agreed') {
1003
1028
  const off = stepOff(asked, a, pairs);
1004
1029
  const amountOff = off === 'another amount';
1005
1030
  if (off) {
@@ -1038,11 +1063,11 @@ export const createOtalessBookings = (deps) => {
1038
1063
  }),
1039
1064
  };
1040
1065
  }
1041
- log(a.autoAccepted
1042
- ? `[otaless] booking at ${a.group}: still refused after a second try with termsAccepted - 8 answered "${forTheLog(msg ?? what, [a.guest.name, a.guest.email, a.guest.phone])}" - not booked`
1043
- : a.groupStep
1044
- ? `[otaless] booking at ${a.group} answered ${what} again, after the guest ${step === 'terms' ? 'agreed to its terms' : 'confirmed it'} - not booked`
1045
- : `[otaless] booking at ${a.group} answered ${what} with no ${step === 'terms' ? 'terms' : 'details'} and token to show the guest - not booked (questions #${step === 'terms' ? 66 : 68})`);
1066
+ // After the guest agreed to the group's own terms - 8's (0.72.1) or a step's.
1067
+ const agreedAlready = !!a.groupStep || a.groupTerms === 'agreed';
1068
+ log(agreedAlready
1069
+ ? `[otaless] booking at ${a.group} answered ${what} again, after the guest ${step === 'terms' ? 'agreed to its terms' : 'confirmed it'} - not booked`
1070
+ : `[otaless] booking at ${a.group} answered ${what} with no ${step === 'terms' ? 'terms' : 'details'} and token to show the guest - not booked (questions #${step === 'terms' ? 66 : 68})`);
1046
1071
  const again = step === 'terms'
1047
1072
  ? `${g.name} asked for its terms to be agreed to again after the guest agreed to them, so nothing was booked or charged.`
1048
1073
  : `${g.name} asked for the booking to be confirmed again after the guest confirmed it, so nothing was booked or charged.`;
@@ -1050,7 +1075,80 @@ export const createOtalessBookings = (deps) => {
1050
1075
  ? `${g.name} asked for terms of its own to be agreed to, which it did not send to be shown here, so nothing was booked or charged.`
1051
1076
  : `${g.name} asked for the booking to be confirmed in a second step, and did not send what to confirm to be shown here, so nothing was booked or charged.`;
1052
1077
  // New codes for the card (酒店平台's next version): until then, these words.
1053
- return { failed: failedStay(a, a.groupStep ? again : none, code) };
1078
+ return { failed: failedStay(a, agreedAlready ? again : none, code) };
1079
+ };
1080
+ /**
1081
+ * 8 answered the group's own terms, and no order (`WireBookingTerms` - the 11-16 document:
1082
+ * asked with `termsRequired: true` at a group whose `/site` says so; robin 11-16, questions
1083
+ * #66). ⚠️ NEVER AGREED FOR THE GUEST (#52): its `termsPoints` and `cancellation`, word
1084
+ * for word, are the guest's to read and agree to themselves - the card's button or the
1085
+ * one-time page; agreed, the room is priced again and 8 sent once more with
1086
+ * `termsRequired: false`, which orders it. Not agreed: nothing more is sent.
1087
+ * ⚠️ NOT HANDED ON: `next` (words for a model - "ask about add-ons before the yes"), the
1088
+ * `summary` (to the log alone, questions #75), `acceptArgs` and `confirmToken` (how they
1089
+ * go back is questions #79 - not kept). For another hotel or room than the one asked,
1090
+ * with nothing to show, too long to show whole, or answered again after the guest agreed:
1091
+ * nothing is shown and nothing booked.
1092
+ */
1093
+ const termsFrom8 = (a, w) => {
1094
+ const g = deps.groupOf(a.group);
1095
+ const guest = [a.guest.name, a.guest.email, a.guest.phone];
1096
+ const note = text(w.summary ?? undefined);
1097
+ if (note)
1098
+ log(`[otaless] booking at ${a.group}: the summary of its terms, kept to this log: "${summaryForLog(note, guest)}"`);
1099
+ const notBooked = (line, why, code) => {
1100
+ log(`[otaless] booking at ${a.group} answered its terms ${line} - not booked`);
1101
+ return { failed: failedStay(a, why, code) };
1102
+ };
1103
+ if (a.groupTerms === 'agreed')
1104
+ return notBooked('again, after the guest agreed to them (questions #79)', `${g.name} asked for its terms to be agreed to again after the guest agreed to them, so nothing was booked or charged.`);
1105
+ const tail = (id) => id.slice(id.lastIndexOf(':') + 1);
1106
+ const hotelSaid = text(w.unifiedHotelId);
1107
+ const roomSaid = text(w.unifiedRoomId);
1108
+ const groupSaid = text(w.providerCode)?.toLowerCase();
1109
+ if ((hotelSaid && tail(hotelSaid) !== tail(a.hotel.id)) ||
1110
+ (roomSaid && tail(roomSaid) !== tail(a.roomId)) ||
1111
+ (groupSaid && groupSaid !== a.group))
1112
+ return notBooked('for another hotel or room than the one asked', `${g.name} sent terms for another hotel or room than the one asked for, so nothing was booked or charged.`);
1113
+ // Word for word, each as the group wrote it - the same twice is shown once.
1114
+ const parts = [];
1115
+ for (const v of [w.termsPoints, w.cancellation]) {
1116
+ const t = typeof v === 'string' ? v.trim() : '';
1117
+ if (t && !parts.some((p) => termsKey(p) === termsKey(t)))
1118
+ parts.push(t);
1119
+ }
1120
+ const shown = parts.join('\n\n');
1121
+ if (!shown)
1122
+ return notBooked('with nothing to show', `${g.name} asked for its own terms to be agreed to and sent none to show here, so nothing was booked or charged.`, 'group-terms');
1123
+ if (shown.length > TERMS_MAX)
1124
+ return notBooked('too long to show whole', `${g.name}'s terms for this room are too long to show in full here, so nothing was booked or charged.`);
1125
+ const unsent = [
1126
+ w.acceptArgs !== undefined && w.acceptArgs !== null ? 'acceptArgs' : '',
1127
+ text(w.confirmToken ?? undefined) ? 'confirmToken' : '',
1128
+ ].filter(Boolean);
1129
+ log(`[otaless] booking at ${a.group} answered its terms (${[text(w.termsPoints ?? undefined) ? 'termsPoints' : '', text(w.cancellation ?? undefined) ? 'cancellation' : ''].filter(Boolean).join(', ')}) - shown to the guest, nothing ordered${unsent.length ? `; ${unsent.join(', ')} not sent back (questions #79)` : ''}`);
1130
+ return {
1131
+ terms: remember({
1132
+ ref: randomBytes(18).toString('base64url'),
1133
+ group: a.group,
1134
+ ...groupWords(a.group),
1135
+ hotelId: a.hotel.id,
1136
+ hotelName: a.hotel.name,
1137
+ ...(a.hotel.names?.name ? { hotelNames: a.hotel.names.name } : {}),
1138
+ roomName: a.roomName,
1139
+ stay: a.stay,
1140
+ rooms: a.rooms,
1141
+ total: a.total,
1142
+ text: shown,
1143
+ source: 'booking',
1144
+ more: true,
1145
+ askedByGroup: 'terms',
1146
+ until: iso(now() + TERMS_MS),
1147
+ owner: a.acct.owner,
1148
+ key: a.acct.key,
1149
+ ask: { roomId: a.roomId, guest: a.guest, groupTerms: 'answered', parts },
1150
+ }),
1151
+ };
1054
1152
  };
1055
1153
  /**
1056
1154
  * The terms an order is held back for (总线程 11-11, D): those kept - or,
@@ -1339,8 +1437,31 @@ export const createOtalessBookings = (deps) => {
1339
1437
  ...(row.currency !== undefined ? { currency: row.currency } : {}),
1340
1438
  }, pairs);
1341
1439
  };
1440
+ /**
1441
+ * An order's terms (8's `cancelPolicy`) are what the guest agreed to: the same words, but
1442
+ * for spacing and punctuation - or, agreed to as 8 answered the group's own terms (0.72.1),
1443
+ * one of the parts they were shown, WHOLE (its `cancellation` alone, say). ⚠️ NEVER A PIECE
1444
+ * OF ONE: "one night is retained" cut out of "after 18:00 the day before, one night is
1445
+ * retained" drops the condition the guest agreed to.
1446
+ */
1447
+ const agreedTo = (said, a) => {
1448
+ const k = termsKey(said);
1449
+ if (k === termsKey(a.agreed))
1450
+ return true;
1451
+ if (a.groupStep?.step === 'terms' && k === termsKey(a.groupStep.text))
1452
+ return true;
1453
+ return a.groupTerms === 'agreed' && (a.agreedParts ?? []).some((p) => termsKey(p) === k);
1454
+ };
1342
1455
  /** What 8 answered, settled: an order to hand on, one held for new terms, or none. */
1343
1456
  const settle = async (a, w, pairs) => {
1457
+ // ⚠️ THE GROUP'S TERMS, NOT AN ORDER (0.72.1): 8 asked with `termsRequired: true`
1458
+ // answers them with no order id - never an order "being looked into" (核对中) below.
1459
+ if (isBookingTerms(w))
1460
+ return termsFrom8(a, w);
1461
+ return settleOrder(a, w, pairs);
1462
+ };
1463
+ /** What 8 answered with - an order, a refusal or nothing - settled (`settle`). */
1464
+ const settleOrder = async (a, w, pairs) => {
1344
1465
  const g = deps.groupOf(a.group);
1345
1466
  // ⚠️ 8's `summary` IS THE BACKEND'S OWN NOTE - TO THE LOG ALONE (0.71.1, 总线程 11-13):
1346
1467
  // Atour's said "未检测到你名下可用的 VCC … 用 ?api_key=<你的 sk_test> 重连 … 会员:<name>
@@ -1369,7 +1490,7 @@ export const createOtalessBookings = (deps) => {
1369
1490
  // Terms of its own to agree to, and no order (questions #66).
1370
1491
  const step = /TERMS/.test(status) ? 'terms' : stepAsked(status);
1371
1492
  if (step)
1372
- return groupAsked(a, step, w, pairs, status);
1493
+ return groupAsked(a, step, w, pairs);
1373
1494
  // Something may be held, under a number we were not told: kept to look for (12).
1374
1495
  const r = recordOf(a, pairs, `pending:${randomBytes(8).toString('hex')}`, '', 'unconfirmed');
1375
1496
  put(r);
@@ -1488,17 +1609,32 @@ export const createOtalessBookings = (deps) => {
1488
1609
  r.stepUnsent = step;
1489
1610
  log(`[otaless] booking ${forTheLog(id)} at ${a.group} answered ${step}_required with nothing to ${step === 'terms' ? 'agree to' : 'confirm'} and no token - handed on with its order, the checks passed (proceedWithoutGroupConfirm; questions #${q})`);
1490
1611
  }
1491
- if (said &&
1492
- termsKey(said) !== termsKey(a.agreed) &&
1493
- !(a.groupStep?.step === 'terms' && termsKey(said) === termsKey(a.groupStep.text))) {
1612
+ // ⚠️ ORDERED WHEN ITS TERMS WERE ASKED FOR, NOTHING AGREED YET (0.72.1): 8 sent with
1613
+ // `termsRequired: true` made the order - a group whose `/site` said it asks for terms
1614
+ // and then did not. The order's own terms - or the room's - are the guest's to agree to
1615
+ // before its page is handed on; with none to show, it is cancelled.
1616
+ // (A room with no terms ordered at once - `noTerms`, proceedWithoutGroupConfirm - is not.)
1617
+ const unagreed = a.groupTerms === 'ask' && !a.agreed && !a.noTerms;
1618
+ const toAgree = unagreed
1619
+ ? (said ?? text(a.roomTerms))
1620
+ : said && !agreedTo(said, a)
1621
+ ? said
1622
+ : undefined;
1623
+ if (unagreed && !toAgree) {
1624
+ log(`[otaless] booking ${forTheLog(id)} at ${a.group} was made when its terms were asked for, with no terms for the guest to agree to - cancelled (questions #79)`);
1625
+ return letGo(a, r, 'terms');
1626
+ }
1627
+ if (toAgree) {
1494
1628
  // ⚠️ NOT THE TERMS AGREED TO: the order stands, its payment page is held
1495
1629
  // back until the guest agrees to these too - not agreed, or not in time,
1496
1630
  // it is cancelled.
1497
- r.terms = said;
1631
+ r.terms = toAgree;
1498
1632
  r.termsNew = true;
1499
1633
  r.held = { until: iso(now() + TERMS_MS) };
1500
1634
  put(r);
1501
- log(`[otaless] booking ${forTheLog(id)} at ${a.group} came with other terms than the guest agreed to - its payment page held back`);
1635
+ log(unagreed
1636
+ ? `[otaless] booking ${forTheLog(id)} at ${a.group} was made when its terms were asked for (termsRequired) - its payment page held back for the guest to agree to its terms (questions #79)`
1637
+ : `[otaless] booking ${forTheLog(id)} at ${a.group} came with other terms than the guest agreed to - its payment page held back`);
1502
1638
  holdFor(r, a.acct.key);
1503
1639
  const t = termsOfHeld(r, a.acct);
1504
1640
  return t ? { terms: t } : { booked: toBooking(r) };
@@ -1508,6 +1644,30 @@ export const createOtalessBookings = (deps) => {
1508
1644
  put(r);
1509
1645
  return { booked: toBooking(r) };
1510
1646
  };
1647
+ /**
1648
+ * ⚠️ THE 7 BEFORE THE GROUP'S TERMS, FOR THE 7 BEFORE THE ORDER (0.72.1): a guest who
1649
+ * agrees within the backend's `@RepeatSubmit` window has the same 7 refused (10014) -
1650
+ * the same member's same room, nights, adults and rooms priced in their session a moment
1651
+ * ago is that price, as `recentQuote` is for the price shown (0.71.2). Only on a 10014,
1652
+ * only `PRICED_IN_MS`, by the sign-in's token - in memory alone.
1653
+ */
1654
+ const pricedIn = new Map();
1655
+ const pricedKey = (a, token) => `${hash(token)}|${a.hotel.id}|${a.roomId}|${a.stay.checkIn}|${a.stay.checkOut}|${a.stay.guests}|${a.rooms}`;
1656
+ const pricedJustNow = (a, token, data) => {
1657
+ const k = pricedKey(a, token);
1658
+ pricedIn.delete(k);
1659
+ pricedIn.set(k, { at: now(), data });
1660
+ while (pricedIn.size > PENDING_MAX) {
1661
+ const first = pricedIn.keys().next().value;
1662
+ if (first === undefined)
1663
+ break;
1664
+ pricedIn.delete(first);
1665
+ }
1666
+ };
1667
+ const pricedRecently = (a, token) => {
1668
+ const hit = pricedIn.get(pricedKey(a, token));
1669
+ return hit && now() - hit.at <= PRICED_IN_MS ? hit.data : undefined;
1670
+ };
1511
1671
  class Moved extends Error {
1512
1672
  }
1513
1673
  class NotPriced extends Error {
@@ -1531,12 +1691,8 @@ export const createOtalessBookings = (deps) => {
1531
1691
  let pairs;
1532
1692
  /** What 8 itself threw, if it did: only that may have made an order. */
1533
1693
  let fromBook;
1534
- /** The step 8 was sent once more for, with `termsAccepted` - see `again`. */
1535
- let autoAccepted;
1536
1694
  /** A refusal for a step naming an order we keep already (`knownNamed`) - see `madeIn`. */
1537
1695
  let namedKnown;
1538
- /** This stay as it was asked, and - once sent again - as agreed for the guest. */
1539
- const as = () => (autoAccepted ? { ...a, autoAccepted } : a);
1540
1696
  let w;
1541
1697
  try {
1542
1698
  w = await withSession(a.acct, a.who, async (cred) => {
@@ -1556,11 +1712,15 @@ export const createOtalessBookings = (deps) => {
1556
1712
  // asked once more after the pause, and a second 10014 is the group's "wait a moment".
1557
1713
  try {
1558
1714
  priced = await ask('once');
1715
+ pricedJustNow(a, cred.token, priced.data);
1559
1716
  }
1560
1717
  catch (err) {
1561
1718
  if (!isCode(err, REPEAT_SUBMIT))
1562
1719
  throw notPriced(err);
1563
- const shown = deps.recentQuote?.(a.hotel, a.roomId, a.stay, a.rooms, cred.token);
1720
+ // The 7 before the group's terms (0.72.1) a moment ago, in this same sign-in - the
1721
+ // guest agreed quickly - or the price the guest was shown.
1722
+ const shown = pricedRecently(a, cred.token) ??
1723
+ deps.recentQuote?.(a.hotel, a.roomId, a.stay, a.rooms, cred.token);
1564
1724
  if (shown) {
1565
1725
  priced = { data: shown };
1566
1726
  log(`[otaless] booking at ${a.group}: 7 answered 10014 - the same quote went in a moment ago; the price the guest was shown then, under the same sign-in, is the one booked at (questions #58)`);
@@ -1593,6 +1753,9 @@ export const createOtalessBookings = (deps) => {
1593
1753
  checkIn: a.stay.checkIn,
1594
1754
  checkOut: a.stay.checkOut,
1595
1755
  roomCount: a.rooms,
1756
+ // 8's own two steps (0.72.1): the group's terms asked for, or - agreed by the
1757
+ // guest themselves - the order. Not sent at a group that asks for no terms.
1758
+ ...(a.groupTerms ? { termsRequired: a.groupTerms === 'ask' } : {}),
1596
1759
  // Only after the guest agreed to the terms 8 asked for (questions #66).
1597
1760
  ...(a.groupStep?.step === 'terms'
1598
1761
  ? { termsToken: a.groupStep.token, termsAccepted: true }
@@ -1647,53 +1810,11 @@ export const createOtalessBookings = (deps) => {
1647
1810
  status: /TERMS/.test(status) || stepAsked(status) ? order.status : String(msg),
1648
1811
  };
1649
1812
  };
1650
- /**
1651
- * ⚠️ AGREED FOR THE GUEST, ONCE (robin 11-12 「流程不用卡」, through 总线程 -
1652
- * `proceedWithoutGroupConfirm`, the dev backend's deployment alone; off
1653
- * before real money): a step 8 asked for with nothing to show and no
1654
- * order - not one the guest already did - is sent once more, in this
1655
- * same session, with `termsAccepted` (item 13's names, borrowed).
1656
- */
1657
- const unshown = (step, data) => step && deps.proceedWithoutGroupConfirm && !a.groupStep && !groupStepOf(step, data)
1658
- ? step
1659
- : undefined;
1660
- const again = async (step) => {
1661
- autoAccepted = step;
1662
- fromBook = undefined;
1663
- log(`[otaless] booking at ${a.group}: 8 answered ${step}_required with nothing to show and no order - sent once more with termsAccepted (proceedWithoutGroupConfirm, robin 11-12; questions #${step === 'terms' ? 66 : 68})`);
1664
- return send({
1665
- ...body,
1666
- termsAccepted: true,
1667
- extraParams: { terms_accepted: true, confirmed: true },
1668
- });
1669
- };
1670
- let booked;
1671
- try {
1672
- booked = await send(body);
1673
- }
1674
- catch (err) {
1675
- if (err === namedKnown?.err)
1676
- throw err;
1677
- const step = err instanceof OtalessError
1678
- ? unshown(stepAsked(err.answer?.msg), err.answer?.data)
1679
- : undefined;
1680
- if (!step)
1681
- throw err;
1682
- booked = await again(step);
1683
- }
1684
- const first = booked.data;
1685
- const said = String(first?.status ?? '')
1686
- .trim()
1687
- .toUpperCase();
1688
- if (!autoAccepted &&
1689
- first &&
1690
- !text(first.unifiedOrderId) &&
1691
- first.success !== false &&
1692
- !text(first.errorMessage ?? undefined)) {
1693
- const step = unshown(/TERMS/.test(said) ? 'terms' : stepAsked(said), first);
1694
- if (step)
1695
- booked = await again(step);
1696
- }
1813
+ // ⚠️ NEVER SENT AGAIN FOR THE GUEST (0.72.1): the second 8 "agreed" with
1814
+ // `termsAccepted` - for a step asked with nothing to show - is gone. The backend took
1815
+ // no such field (11-12, questions #66), and a group that asks for terms now answers
1816
+ // them itself (`termsRequired`); a step asked with nothing to show is not booked.
1817
+ const booked = await send(body);
1697
1818
  const back = booked.session ?? priced.session;
1698
1819
  return { data: booked.data, ...(back ? { session: back } : {}) };
1699
1820
  });
@@ -1718,30 +1839,28 @@ export const createOtalessBookings = (deps) => {
1718
1839
  // repeat of one that went in a moment ago (10014) - may have made it.
1719
1840
  // Kept to look for in the group's order list (12), said as not known.
1720
1841
  if (err === fromBook && (unanswered(err) || isCode(err, REPEAT_SUBMIT))) {
1721
- // `as()`: the second 8 - agreed for the guest - is what may have made it
1722
- // (总线程's review of 0.68.0, P3); its booking says so like any other.
1723
- const r = recordOf(as(), pairs ?? { orig: a.total }, `pending:${randomBytes(8).toString('hex')}`, '', 'unconfirmed');
1842
+ const r = recordOf(a, pairs ?? { orig: a.total }, `pending:${randomBytes(8).toString('hex')}`, '', 'unconfirmed');
1724
1843
  put(r);
1725
1844
  return { booked: toBooking(r) };
1726
1845
  }
1727
1846
  if (namedKnown && err === namedKnown.err)
1728
- return untouched(as(), namedKnown.id, 'refused');
1847
+ return untouched(a, namedKnown.id, 'refused');
1729
1848
  // ⚠️ 8 REFUSED FOR TERMS (robin 11-11 18:30, Ascott: code 500 "terms_required").
1730
1849
  const step = err === fromBook && err instanceof OtalessError ? stepAsked(err.answer?.msg) : undefined;
1731
1850
  if (step)
1732
- return groupAsked(as(), step, err instanceof OtalessError ? err.answer?.data : undefined, pairs ?? { orig: a.total }, err instanceof OtalessError ? err.answer?.msg : undefined);
1851
+ return groupAsked(a, step, err instanceof OtalessError ? err.answer?.data : undefined, pairs ?? { orig: a.total });
1733
1852
  const ref = err === fromBook && err instanceof OtalessError
1734
- ? refusalOf(as(), err.answer?.data, err.answer?.msg)
1853
+ ? refusalOf(a, err.answer?.data, err.answer?.msg)
1735
1854
  : undefined;
1736
1855
  if (ref)
1737
- return refusedWithOrder(as(), ref, pairs ?? { orig: a.total });
1856
+ return refusedWithOrder(a, ref, pairs ?? { orig: a.total });
1738
1857
  if (err instanceof OtalessError)
1739
1858
  return {
1740
1859
  failed: failedStay(a, `${g.name} did not take the booking, so nothing was booked or charged.`),
1741
1860
  };
1742
1861
  throw err;
1743
1862
  }
1744
- return settle(as(), w, pairs ?? { orig: a.total });
1863
+ return settle(a, w, pairs ?? { orig: a.total });
1745
1864
  };
1746
1865
  /**
1747
1866
  * An order row that could be an order 8 did not answer for: of the group,
@@ -2002,12 +2121,41 @@ export const createOtalessBookings = (deps) => {
2002
2121
  guest: g0,
2003
2122
  total: line.total,
2004
2123
  };
2124
+ // ⚠️ WHETHER THE GROUP ASKS FOR ITS OWN TERMS: its `/site` row (the 11-16 document,
2125
+ // 0.72.1) - `true`: 8 itself is asked for them now (`termsRequired: true`, nothing is
2126
+ // ordered), and they - not the room's - are what the guest agrees to; `false`: the
2127
+ // room's terms, and one 8 orders it, as before; not said (not listed, a backend before
2128
+ // the document, `/site` not read since): the room's terms first, and 8 is then sent
2129
+ // with `termsRequired: true` all the same - a group that asks for terms answers them,
2130
+ // and any other orders it, as the document has it.
2131
+ const needsTerms = await groupTermsOf(group);
2132
+ if (needsTerms) {
2133
+ inFlight.add(lockKey);
2134
+ try {
2135
+ const out = await place({ ...ask, agreed: '', roomTerms: agreed, groupTerms: 'ask' });
2136
+ if (out.booked)
2137
+ booked.push(out.booked);
2138
+ if (out.failed)
2139
+ failed.push(out.failed);
2140
+ if (out.terms)
2141
+ terms.push(out.terms);
2142
+ }
2143
+ finally {
2144
+ inFlight.delete(lockKey);
2145
+ }
2146
+ continue;
2147
+ }
2148
+ const unsaid = needsTerms === undefined;
2005
2149
  // No terms for this room to agree to, and the deployment lets that go on
2006
2150
  // (robin 11-12 「条款没有也让走下一步」): ordered now - said on the booking.
2007
2151
  if (!agreed && deps.proceedWithoutGroupConfirm) {
2008
2152
  inFlight.add(lockKey);
2009
2153
  try {
2010
- const out = await place({ ...ask, noTerms: true });
2154
+ const out = await place({
2155
+ ...ask,
2156
+ noTerms: true,
2157
+ ...(unsaid ? { groupTerms: 'ask' } : {}),
2158
+ });
2011
2159
  if (out.booked)
2012
2160
  booked.push(out.booked);
2013
2161
  if (out.failed)
@@ -2021,7 +2169,7 @@ export const createOtalessBookings = (deps) => {
2021
2169
  continue;
2022
2170
  }
2023
2171
  // ⚠️ NOTHING IS ORDERED YET (§15.1): the terms first, for the guest to agree to.
2024
- terms.push(termsBefore(ask));
2172
+ terms.push(termsBefore(ask, unsaid));
2025
2173
  }
2026
2174
  return {
2027
2175
  booked,
@@ -2107,6 +2255,13 @@ export const createOtalessBookings = (deps) => {
2107
2255
  ...(ask.token
2108
2256
  ? { groupStep: { step: ask.step ?? 'terms', text: p.text, token: ask.token } }
2109
2257
  : {}),
2258
+ // 8's own two steps (0.72.1): the group's terms as 8 answered them, agreed - the
2259
+ // order now; or the room's, at a group whose `/site` did not say - 8 asks for them.
2260
+ ...(ask.groupTerms === 'answered'
2261
+ ? { groupTerms: 'agreed', ...(ask.parts ? { agreedParts: ask.parts } : {}) }
2262
+ : ask.groupTerms === 'ask'
2263
+ ? { groupTerms: 'ask' }
2264
+ : {}),
2110
2265
  guest: ask.guest,
2111
2266
  total: p.total,
2112
2267
  });