@curless/hotel-storefront 0.62.0 → 0.63.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-ota.d.ts +9 -0
- package/dist/account/fake-ota.d.ts.map +1 -1
- package/dist/account/fake-ota.js +7 -2
- package/dist/account/fake-ota.js.map +1 -1
- package/dist/account/index.d.ts +28 -0
- package/dist/account/index.d.ts.map +1 -1
- package/dist/account/index.js +402 -2
- package/dist/account/index.js.map +1 -1
- package/dist/account/pages.d.ts +99 -0
- package/dist/account/pages.d.ts.map +1 -1
- package/dist/account/pages.js +228 -4
- package/dist/account/pages.js.map +1 -1
- package/dist/account/requests.d.ts +11 -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/backend.d.ts +27 -0
- package/dist/backend.d.ts.map +1 -1
- package/dist/backend.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/config.d.ts +23 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +10 -0
- package/dist/config.js.map +1 -1
- package/dist/legal.d.ts.map +1 -1
- package/dist/legal.js +34 -22
- package/dist/legal.js.map +1 -1
- package/dist/otaless/backend.d.ts +31 -1
- package/dist/otaless/backend.d.ts.map +1 -1
- package/dist/otaless/backend.js +31 -17
- package/dist/otaless/backend.js.map +1 -1
- package/dist/otaless/booking.d.ts +14 -1
- package/dist/otaless/booking.d.ts.map +1 -1
- package/dist/otaless/booking.js +17 -10
- package/dist/otaless/booking.js.map +1 -1
- package/dist/otaless/client.d.ts +11 -0
- package/dist/otaless/client.d.ts.map +1 -1
- package/dist/otaless/client.js +20 -3
- package/dist/otaless/client.js.map +1 -1
- package/dist/otaless/make.d.ts.map +1 -1
- package/dist/otaless/make.js +17 -1
- package/dist/otaless/make.js.map +1 -1
- package/dist/server.d.ts +2 -2
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +73 -3
- package/dist/server.js.map +1 -1
- package/dist/surface.d.ts +6 -0
- package/dist/surface.d.ts.map +1 -1
- package/dist/surface.js +71 -23
- package/dist/surface.js.map +1 -1
- package/dist/tools.d.ts +230 -52
- package/dist/tools.d.ts.map +1 -1
- package/dist/tools.js +838 -225
- package/dist/tools.js.map +1 -1
- package/dist/types.d.ts +32 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/tools.js
CHANGED
|
@@ -146,6 +146,13 @@ export const withheldTools = (n, caps) => new Set([
|
|
|
146
146
|
...(caps.changes || caps.extras ? [] : [n.previewChange, n.changeBooking]),
|
|
147
147
|
...(caps.policies === false ? [n.policies] : []),
|
|
148
148
|
...(caps.unionpay ? [] : [n.payWithUnionPay]),
|
|
149
|
+
// The group's own checkout (Otaless 0.63.0): the card's agreement to its
|
|
150
|
+
// terms, a paid booking's refund, and the add-ons after a booking - each
|
|
151
|
+
// listed only where the backend says it has them, and never where nothing
|
|
152
|
+
// can be booked.
|
|
153
|
+
...(caps.groupCheckout && !caps.readOnly ? [] : [n.acceptTerms]),
|
|
154
|
+
...(caps.refunds && !caps.readOnly ? [] : [n.refundBooking]),
|
|
155
|
+
...(caps.addons && !caps.readOnly ? [] : [n.listBookingAddons, n.addBookingAddon]),
|
|
149
156
|
// Nothing can be booked here yet (`readOnly`, Otaless 2026-11-03): no tool
|
|
150
157
|
// that books, finds, changes or cancels a booking - the card's own two
|
|
151
158
|
// for Reserve included, so no button that books is drawn.
|
|
@@ -333,6 +340,15 @@ const forCapabilities = (tools, n, v, caps) => {
|
|
|
333
340
|
}
|
|
334
341
|
if (!caps.members)
|
|
335
342
|
out = { ...out, inputSchema: without(out.inputSchema, 'rememberRequests') };
|
|
343
|
+
// ⚠️ THE GROUP'S OWN CHECKOUT (Otaless 0.63.0): a booking is an order with
|
|
344
|
+
// the group, which may first send its terms back for the GUEST to agree
|
|
345
|
+
// to, and is paid on the group's own page. One list for every client, so
|
|
346
|
+
// "the card or a one-time page" - never a card alone.
|
|
347
|
+
if (t.name === n.requestBooking && caps.groupCheckout)
|
|
348
|
+
out = {
|
|
349
|
+
...out,
|
|
350
|
+
description: `Books the trip's rooms for a named guest through each hotel group's own checkout, one order per stay with the group that stay belongs to. The group may first send its booking terms back for the guest to read and agree to themselves - on the card or on a one-time page, not in the chat - and its payment page, with its host and the time to pay by, is then in the answer. A stay is booked once it is paid; the bookings list says when it has been. Preferences - a bed type, a floor, a late arrival - ride along on the booking as requests.`,
|
|
351
|
+
};
|
|
336
352
|
// A market's suppliers book differently - its own description says so.
|
|
337
353
|
if (t.name === n.requestBooking && caps.booking === 'pay-at-hotel' && !v.market) {
|
|
338
354
|
out = {
|
|
@@ -1063,8 +1079,97 @@ const allTools = (n, v) => {
|
|
|
1063
1079
|
required: ['name', 'email'],
|
|
1064
1080
|
},
|
|
1065
1081
|
},
|
|
1082
|
+
{
|
|
1083
|
+
// ⚠️ THE CARD'S, NEVER THE MODEL'S (`ui.visibility: ['app']`, server.ts),
|
|
1084
|
+
// AND NO PARAMETER HERE (OR ON ANY TOOL) MEANS "AGREED": the guest's
|
|
1085
|
+
// press on "Agree and continue" is the whole of the agreement, and
|
|
1086
|
+
// `ref` only says which terms the card was showing.
|
|
1087
|
+
name: n.acceptTerms,
|
|
1088
|
+
description: `The card's own step when the guest presses "Agree and continue" under a hotel group's booking terms: it sends the guest's agreement to the terms behind \`ref\` and the stay is then booked with the group. It answers like a booking: the group's payment page, the terms again, or why nothing was booked.`,
|
|
1089
|
+
annotations: books(`Agree to booking terms on ${v.brand}`, open),
|
|
1090
|
+
inputSchema: {
|
|
1091
|
+
type: 'object',
|
|
1092
|
+
properties: {
|
|
1093
|
+
ref: {
|
|
1094
|
+
type: 'string',
|
|
1095
|
+
description: 'The terms the card is showing, by the reference the booking answer gave',
|
|
1096
|
+
},
|
|
1097
|
+
},
|
|
1098
|
+
required: ['ref'],
|
|
1099
|
+
},
|
|
1100
|
+
},
|
|
1101
|
+
{
|
|
1102
|
+
name: n.refundBooking,
|
|
1103
|
+
description: 'Asks the hotel group to refund, in full, a booking made here that has been paid. It is meant for a guest who asked for their money back, once the booking and the amount have been said back to them. The answer says what the group did with the request.',
|
|
1104
|
+
annotations: cancels('Refund a booking', open),
|
|
1105
|
+
inputSchema: {
|
|
1106
|
+
type: 'object',
|
|
1107
|
+
properties: {
|
|
1108
|
+
booking: {
|
|
1109
|
+
type: 'string',
|
|
1110
|
+
description: 'The confirmation code or order id, as the booking answer gave it',
|
|
1111
|
+
},
|
|
1112
|
+
reason: {
|
|
1113
|
+
type: 'string',
|
|
1114
|
+
maxLength: REFUND_REASON_MAX,
|
|
1115
|
+
description: `Optional, the guest's reason in their own words, up to ${REFUND_REASON_MAX} characters`,
|
|
1116
|
+
},
|
|
1117
|
+
},
|
|
1118
|
+
required: ['booking'],
|
|
1119
|
+
},
|
|
1120
|
+
},
|
|
1121
|
+
{
|
|
1122
|
+
name: n.listBookingAddons,
|
|
1123
|
+
description: 'What can be added to a booking made here after it was made - an airport transfer and the like - each with its id, name, price and the details it needs. Only a booking made here has any.',
|
|
1124
|
+
annotations: reads('Add-ons for a booking', open),
|
|
1125
|
+
inputSchema: {
|
|
1126
|
+
type: 'object',
|
|
1127
|
+
properties: {
|
|
1128
|
+
booking: {
|
|
1129
|
+
type: 'string',
|
|
1130
|
+
description: 'The confirmation code or order id, as the booking answer gave it',
|
|
1131
|
+
},
|
|
1132
|
+
},
|
|
1133
|
+
required: ['booking'],
|
|
1134
|
+
},
|
|
1135
|
+
},
|
|
1136
|
+
{
|
|
1137
|
+
name: n.addBookingAddon,
|
|
1138
|
+
description: "Adds one add-on to a booking made here, at the price the add-on list gave. It is meant for an add-on the guest chose, once its price has been said back to them. The answer gives the add-on order's code, status and total.",
|
|
1139
|
+
annotations: books('Add an add-on to a booking', open),
|
|
1140
|
+
inputSchema: {
|
|
1141
|
+
type: 'object',
|
|
1142
|
+
properties: {
|
|
1143
|
+
booking: {
|
|
1144
|
+
type: 'string',
|
|
1145
|
+
description: 'The confirmation code or order id, as the booking answer gave it',
|
|
1146
|
+
},
|
|
1147
|
+
addon: { type: 'string', description: 'The add-on id, as the add-on list gave it' },
|
|
1148
|
+
direction: {
|
|
1149
|
+
type: 'string',
|
|
1150
|
+
enum: ['arrival', 'departure', 'round_trip'],
|
|
1151
|
+
description: 'For a transfer: to the hotel, from it, or both',
|
|
1152
|
+
},
|
|
1153
|
+
flightNo: {
|
|
1154
|
+
type: 'string',
|
|
1155
|
+
description: 'For a transfer: the flight number, e.g. MU5101',
|
|
1156
|
+
},
|
|
1157
|
+
pickupTime: { type: 'string', description: 'For a transfer: the pick-up time, HH:MM' },
|
|
1158
|
+
date: { type: 'string', description: 'The date it is for, YYYY-MM-DD' },
|
|
1159
|
+
quantity: {
|
|
1160
|
+
type: 'integer',
|
|
1161
|
+
minimum: 1,
|
|
1162
|
+
maximum: 20,
|
|
1163
|
+
description: 'How many, 1 to 20. Default 1',
|
|
1164
|
+
},
|
|
1165
|
+
},
|
|
1166
|
+
required: ['booking', 'addon'],
|
|
1167
|
+
},
|
|
1168
|
+
},
|
|
1066
1169
|
];
|
|
1067
1170
|
};
|
|
1171
|
+
/** A guest's reason for a refund, as the group's staff are sent it (`otaless/booking.ts`). */
|
|
1172
|
+
const REFUND_REASON_MAX = 200;
|
|
1068
1173
|
// The shape of each tool's `structuredContent`, so a reader knows what it is
|
|
1069
1174
|
// holding without inferring it from one example.
|
|
1070
1175
|
//
|
|
@@ -1140,7 +1245,12 @@ const TRIP_SCHEMA = {
|
|
|
1140
1245
|
const CANCEL_SCHEMA = {
|
|
1141
1246
|
type: 'object',
|
|
1142
1247
|
properties: {
|
|
1143
|
-
view: { enum: ['cancellation-preview', 'cancelled', 'booking-not-found'] },
|
|
1248
|
+
view: { enum: ['cancellation-preview', 'cancelled', 'booking-not-found', 'error'] },
|
|
1249
|
+
/** The fee is not known before the group cancels: `rule` is its terms and no fee is said. */
|
|
1250
|
+
feeUnknown: BOOL,
|
|
1251
|
+
error: STR,
|
|
1252
|
+
detail: STR,
|
|
1253
|
+
groups: ARR,
|
|
1144
1254
|
/** The coupon the booking used and whether cancelling gives it back. */
|
|
1145
1255
|
coupon: OBJ,
|
|
1146
1256
|
brand: STR,
|
|
@@ -1325,9 +1435,20 @@ const BOOKING_SCHEMA = {
|
|
|
1325
1435
|
properties: {
|
|
1326
1436
|
// `trip`: nothing was booked and the trip is shown again - its price
|
|
1327
1437
|
// moved, or (in a market) it holds two groups' stays.
|
|
1328
|
-
|
|
1438
|
+
// `terms`: a group sent its booking terms back for the GUEST to agree to - the
|
|
1439
|
+
// stay is neither booked nor failed yet (`terms`, `termsSaid`).
|
|
1440
|
+
view: { enum: ['booking', 'needs-guest', 'empty-trip', 'error', 'trip', 'terms'] },
|
|
1329
1441
|
/** `coupon`: nothing was booked because the coupon asked for cannot be used (`couponRefused`). */
|
|
1330
1442
|
notBooked: STR,
|
|
1443
|
+
/** `terms`: the terms waiting for the guest, word for word (`termsOf`). */
|
|
1444
|
+
terms: ARR,
|
|
1445
|
+
/** `terms`: the sentence that says the guest agrees to them themselves, as the text says it. */
|
|
1446
|
+
termsSaid: STR,
|
|
1447
|
+
/** `error`: why, as a code (`BOOKING_REFUSALS` or 'card-only') and in the guest's words. */
|
|
1448
|
+
error: STR,
|
|
1449
|
+
detail: STR,
|
|
1450
|
+
/** A sign-in refusal: the groups the guest must sign in to, `{ code, name, names? }`. */
|
|
1451
|
+
groups: ARR,
|
|
1331
1452
|
coupon: OBJ,
|
|
1332
1453
|
couponRefused: OBJ,
|
|
1333
1454
|
coupons: ARR,
|
|
@@ -1503,7 +1624,10 @@ export const buildOutputSchemas = (n) => ({
|
|
|
1503
1624
|
[n.listBookings]: {
|
|
1504
1625
|
type: 'object',
|
|
1505
1626
|
properties: {
|
|
1506
|
-
view: {
|
|
1627
|
+
view: { enum: ['bookings', 'error'] },
|
|
1628
|
+
error: STR,
|
|
1629
|
+
detail: STR,
|
|
1630
|
+
groups: ARR,
|
|
1507
1631
|
brand: STR,
|
|
1508
1632
|
toolNames: OBJ,
|
|
1509
1633
|
bookingMode: STR,
|
|
@@ -1516,6 +1640,61 @@ export const buildOutputSchemas = (n) => ({
|
|
|
1516
1640
|
},
|
|
1517
1641
|
[n.previewCancellation]: CANCEL_SCHEMA,
|
|
1518
1642
|
[n.cancelBooking]: CANCEL_SCHEMA,
|
|
1643
|
+
// The group's own checkout (0.63.0): the card's agreement answers like a booking.
|
|
1644
|
+
[n.acceptTerms]: BOOKING_SCHEMA,
|
|
1645
|
+
[n.refundBooking]: {
|
|
1646
|
+
type: 'object',
|
|
1647
|
+
properties: {
|
|
1648
|
+
view: { enum: ['booking', 'booking-not-found', 'error'] },
|
|
1649
|
+
brand: STR,
|
|
1650
|
+
toolNames: OBJ,
|
|
1651
|
+
bookingMode: STR,
|
|
1652
|
+
demo: BOOL,
|
|
1653
|
+
booking: OBJ,
|
|
1654
|
+
total: STR,
|
|
1655
|
+
/** The refund was asked for; the booking's `payment` says where it stands. */
|
|
1656
|
+
refundAsked: BOOL,
|
|
1657
|
+
query: STR,
|
|
1658
|
+
error: STR,
|
|
1659
|
+
detail: STR,
|
|
1660
|
+
groups: ARR,
|
|
1661
|
+
},
|
|
1662
|
+
required: ['view'],
|
|
1663
|
+
},
|
|
1664
|
+
[n.listBookingAddons]: {
|
|
1665
|
+
type: 'object',
|
|
1666
|
+
properties: {
|
|
1667
|
+
view: { enum: ['booking-addons', 'booking-not-found', 'error'] },
|
|
1668
|
+
brand: STR,
|
|
1669
|
+
toolNames: OBJ,
|
|
1670
|
+
bookingMode: STR,
|
|
1671
|
+
demo: BOOL,
|
|
1672
|
+
booking: STR,
|
|
1673
|
+
addons: ARR,
|
|
1674
|
+
query: STR,
|
|
1675
|
+
error: STR,
|
|
1676
|
+
detail: STR,
|
|
1677
|
+
groups: ARR,
|
|
1678
|
+
},
|
|
1679
|
+
required: ['view'],
|
|
1680
|
+
},
|
|
1681
|
+
[n.addBookingAddon]: {
|
|
1682
|
+
type: 'object',
|
|
1683
|
+
properties: {
|
|
1684
|
+
view: { enum: ['booking-addon', 'booking-not-found', 'error'] },
|
|
1685
|
+
brand: STR,
|
|
1686
|
+
toolNames: OBJ,
|
|
1687
|
+
bookingMode: STR,
|
|
1688
|
+
demo: BOOL,
|
|
1689
|
+
booking: STR,
|
|
1690
|
+
addon: OBJ,
|
|
1691
|
+
query: STR,
|
|
1692
|
+
error: STR,
|
|
1693
|
+
detail: STR,
|
|
1694
|
+
groups: ARR,
|
|
1695
|
+
},
|
|
1696
|
+
required: ['view'],
|
|
1697
|
+
},
|
|
1519
1698
|
[n.previewChange]: CHANGE_SCHEMA,
|
|
1520
1699
|
[n.changeBooking]: CHANGE_SCHEMA,
|
|
1521
1700
|
[n.compare]: {
|
|
@@ -1733,6 +1912,12 @@ const partyOnTrip = (deps, key, hotelId, args) => {
|
|
|
1733
1912
|
* membership number on every call is carrying it further than it has to go.
|
|
1734
1913
|
*/
|
|
1735
1914
|
const memberBadge = (deps, key) => {
|
|
1915
|
+
// ⚠️ NOTHING WHERE THERE IS NO MEMBERSHIP SIGN-IN (0.63.0): Otaless has none
|
|
1916
|
+
// (\`capabilities.members\`), and \`signedIn: false\` beside a booking made with the
|
|
1917
|
+
// guest's Otaless account was read by the model as "you are not signed in" -
|
|
1918
|
+
// twice in one eval run. The account's own sign-in is said by the account.
|
|
1919
|
+
if (!(deps.backend.capabilities ?? FULL_CAPABILITIES).members)
|
|
1920
|
+
return {};
|
|
1736
1921
|
const m = deps.members.read(key);
|
|
1737
1922
|
// ⚠️ `signedIn` ON EVERY ANSWER, false included. The card cleared its tier
|
|
1738
1923
|
// chip only on the sign-out view, so after signing out in the chat - or a
|
|
@@ -1897,6 +2082,11 @@ const bookingForCard = (b) => ({
|
|
|
1897
2082
|
? {
|
|
1898
2083
|
payment: {
|
|
1899
2084
|
...b.payment,
|
|
2085
|
+
// ⚠️ WHERE THE GUEST IS SENT AND BY WHEN, in words (Otaless 0.63.0, all
|
|
2086
|
+
// brands): the host of the payment page, and the pay-by moment with its
|
|
2087
|
+
// offset - never a bare ISO string. The card and the model read the same.
|
|
2088
|
+
...(hostOf(b.payment.url) ? { host: hostOf(b.payment.url) } : {}),
|
|
2089
|
+
...(payByWords(b.payment) ? { payByWords: payByWords(b.payment) } : {}),
|
|
1900
2090
|
amount: formatMoney(b.payment.amount),
|
|
1901
2091
|
// What goes back, where it is not the whole amount, as text too - the
|
|
1902
2092
|
// cancelled page says "¥1,601 of the ¥3,202 paid" from it (robin,
|
|
@@ -1992,7 +2182,7 @@ const paidLine = (deps, b, fee) => {
|
|
|
1992
2182
|
? `Once UnionPay issues its one-time card, the booking is made here - it is not sent to ${h.name}`
|
|
1993
2183
|
: `Once UnionPay issues its one-time card, the stay is booked with ${h.name}, who charges that card`}; not confirmed by then, nothing is booked or charged.`
|
|
1994
2184
|
: p.url
|
|
1995
|
-
? `**Not booked yet.** ${amount} is to be paid on the card page by ${p.payByLocal
|
|
2185
|
+
? `**Not booked yet.** ${amount} is to be paid on ${hostOf(p.url) ?? 'the card page'}${payByWords(p) ? ` by ${payByWords(p)}${p.payByLocal ? ' hotel time' : ''}` : ''}: ${p.url}. ${
|
|
1996
2186
|
// ⚠️ NOT "BOOKED WITH" A GROUP IT IS NEVER SENT TO (0.55.7, 总线程 11-05).
|
|
1997
2187
|
h.notReal
|
|
1998
2188
|
? `Once it is paid the booking is made here - it is not sent to ${h.name} - and ${deps.tools.listBookings} shows it`
|
|
@@ -3273,6 +3463,178 @@ const listedForCard = (deps, b) => {
|
|
|
3273
3463
|
const said = notSentStatus(deps, b);
|
|
3274
3464
|
return { ...bookingForCard(b), ...(said ? { statusSaid: said } : {}) };
|
|
3275
3465
|
};
|
|
3466
|
+
/**
|
|
3467
|
+
* The host a payment page is on - what a guest checks before they pay - or
|
|
3468
|
+
* nothing when the address is not one.
|
|
3469
|
+
*/
|
|
3470
|
+
const hostOf = (url) => {
|
|
3471
|
+
if (!url)
|
|
3472
|
+
return undefined;
|
|
3473
|
+
try {
|
|
3474
|
+
return new URL(url).host || undefined;
|
|
3475
|
+
}
|
|
3476
|
+
catch {
|
|
3477
|
+
return undefined;
|
|
3478
|
+
}
|
|
3479
|
+
};
|
|
3480
|
+
const MONTHS = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
|
|
3481
|
+
/**
|
|
3482
|
+
* A moment as a clock time with its offset - "17:30 UTC+08:00, 10 Nov" - never
|
|
3483
|
+
* a bare ISO string. Read from the string itself: its own offset when it has
|
|
3484
|
+
* one, else UTC, since no hotel record here carries a time zone. Undefined for
|
|
3485
|
+
* anything that is not an ISO moment.
|
|
3486
|
+
*/
|
|
3487
|
+
export const clockWords = (iso) => {
|
|
3488
|
+
const m = /^(\d{4})-(\d{2})-(\d{2})[T ](\d{2}):(\d{2})(?::\d{2}(?:\.\d+)?)?(Z|[+-]\d{2}:?\d{2})?$/.exec(iso ?? '');
|
|
3489
|
+
if (!m)
|
|
3490
|
+
return undefined;
|
|
3491
|
+
const [, , mo, d, hh, mm, zone] = m;
|
|
3492
|
+
const offset = !zone || zone === 'Z'
|
|
3493
|
+
? 'UTC'
|
|
3494
|
+
: `UTC${zone.slice(0, 3)}:${zone.length === 6 ? zone.slice(4) : zone.slice(3)}`;
|
|
3495
|
+
return `${hh}:${mm} ${offset}, ${Number(d)} ${MONTHS[Number(mo) - 1] ?? mo}`;
|
|
3496
|
+
};
|
|
3497
|
+
/** When a payment page is paid by: the hotel's own clock where the backend gave it, else the moment with its offset. */
|
|
3498
|
+
const payByWords = (p) => p.payByLocal ?? clockWords(p.payBy);
|
|
3499
|
+
/**
|
|
3500
|
+
* The refusals `otaless/booking.ts` raises with a `code` (docs §13.5): each is
|
|
3501
|
+
* answered as `view: 'error'` with the code itself, never as the generic
|
|
3502
|
+
* 'not-bookable' / 'uncertain' - the card says each in its own words, and its
|
|
3503
|
+
* `detail` is already the guest's.
|
|
3504
|
+
*/
|
|
3505
|
+
const BOOKING_REFUSALS = new Set([
|
|
3506
|
+
'sign-in',
|
|
3507
|
+
'signed-out',
|
|
3508
|
+
'session-expired',
|
|
3509
|
+
'guest',
|
|
3510
|
+
'terms-gone',
|
|
3511
|
+
'unconfirmed',
|
|
3512
|
+
'not-cancelled',
|
|
3513
|
+
'not-paid',
|
|
3514
|
+
'not-refunded',
|
|
3515
|
+
'unknown-addon',
|
|
3516
|
+
'addon',
|
|
3517
|
+
'price-changed',
|
|
3518
|
+
]);
|
|
3519
|
+
/** The three that mean "sign in at this group": they carry the groups (`groups`, provider codes). */
|
|
3520
|
+
const SIGN_IN_REFUSALS = new Set(['sign-in', 'signed-out', 'session-expired']);
|
|
3521
|
+
/**
|
|
3522
|
+
* The answer to a booking refusal, or undefined when `err` is not one.
|
|
3523
|
+
*
|
|
3524
|
+
* ⚠️ `groups` IS READ DEFENSIVELY: a refusal that carries none says nothing of
|
|
3525
|
+
* where to sign in. Per group: the account's link tool with that group's code
|
|
3526
|
+
* where the deployment has one (`ToolDeps.groupSignIn`), else its sign-in tool.
|
|
3527
|
+
*/
|
|
3528
|
+
const refusalAnswer = (deps, key, err) => {
|
|
3529
|
+
const e = err;
|
|
3530
|
+
if (!(e instanceof Error) || typeof e.code !== 'string' || !BOOKING_REFUSALS.has(e.code))
|
|
3531
|
+
return undefined;
|
|
3532
|
+
const codes = SIGN_IN_REFUSALS.has(e.code) && Array.isArray(e.groups)
|
|
3533
|
+
? [...new Set(e.groups.filter((g) => typeof g === 'string' && !!g))]
|
|
3534
|
+
: [];
|
|
3535
|
+
const suppliers = deps.backend.suppliers?.() ?? [];
|
|
3536
|
+
const groups = codes.map((code) => {
|
|
3537
|
+
const s = suppliers.find((x) => x.id === code);
|
|
3538
|
+
return { code, name: s?.name ?? code, ...(s?.names ? { names: s.names } : {}) };
|
|
3539
|
+
});
|
|
3540
|
+
const how = deps.groupSignIn;
|
|
3541
|
+
const signIn = groups
|
|
3542
|
+
.map((g) => how?.linkTool
|
|
3543
|
+
? `To sign in at ${g.name}: ${how.linkTool} with group "${g.code}" gives the guest a one-time page for it.`
|
|
3544
|
+
: how?.signInTool
|
|
3545
|
+
? `${how.signInTool} gives the guest a one-time page to sign in to their ${deps.vocab.brand} account.`
|
|
3546
|
+
: '')
|
|
3547
|
+
.filter((x, i, all) => !!x && all.indexOf(x) === i);
|
|
3548
|
+
return {
|
|
3549
|
+
structured: {
|
|
3550
|
+
view: 'error',
|
|
3551
|
+
...common(deps, key),
|
|
3552
|
+
error: e.code,
|
|
3553
|
+
detail: e.message,
|
|
3554
|
+
...(groups.length ? { groups } : {}),
|
|
3555
|
+
},
|
|
3556
|
+
text: [e.message, ...signIn].join(' '),
|
|
3557
|
+
};
|
|
3558
|
+
};
|
|
3559
|
+
/** The longest stretch of a group's terms put in the text for the model; the card has all of it. */
|
|
3560
|
+
const TERMS_TEXT_MAX = 2_000;
|
|
3561
|
+
/**
|
|
3562
|
+
* Terms a group sent back, for the GUEST to agree to - as the structure and as
|
|
3563
|
+
* words, in the two kinds of host.
|
|
3564
|
+
*
|
|
3565
|
+
* ⚠️ THE MODEL CANNOT AGREE FOR THE GUEST, and no tool parameter means "agreed":
|
|
3566
|
+
* the card's button (`acceptTerms`, the card's own tool) or the one-time page
|
|
3567
|
+
* is the only way, and the words say so first. The text and the structure say
|
|
3568
|
+
* the same (`termsSaid`) - the model reads the structure.
|
|
3569
|
+
*/
|
|
3570
|
+
const termsAnswer = (deps, ctx, key, terms) => {
|
|
3571
|
+
const t = deps.tools;
|
|
3572
|
+
const groupNames = [...new Set(terms.map((x) => withZh(x.groupName, x.groupNames, ctx.noCards)))];
|
|
3573
|
+
const many = groupNames.length > 1;
|
|
3574
|
+
const termsSaid = `Not booked yet: ${listAnd(groupNames)} ${many ? 'ask' : 'asks'} the guest to read and agree to ${many ? 'their' : 'its'} booking terms themselves first - you cannot agree for them, and do not ask them to say they agree in the chat.`;
|
|
3575
|
+
const entries = terms.map((x) => {
|
|
3576
|
+
const link = ctx.noCards ? deps.termsLink?.(key, x.ref) : undefined;
|
|
3577
|
+
const cut = ctx.noCards && x.text.length > TERMS_TEXT_MAX;
|
|
3578
|
+
return {
|
|
3579
|
+
entry: {
|
|
3580
|
+
ref: x.ref,
|
|
3581
|
+
group: x.group,
|
|
3582
|
+
groupName: x.groupName,
|
|
3583
|
+
...(x.groupNames ? { groupNames: x.groupNames } : {}),
|
|
3584
|
+
hotelId: x.hotelId,
|
|
3585
|
+
hotelName: x.hotelName,
|
|
3586
|
+
...(x.hotelNames ? { hotelNames: x.hotelNames } : {}),
|
|
3587
|
+
roomName: x.roomName,
|
|
3588
|
+
stay: x.stay,
|
|
3589
|
+
rooms: x.rooms,
|
|
3590
|
+
total: formatMoney(x.total),
|
|
3591
|
+
totalMoney: x.total,
|
|
3592
|
+
// A client with no card is handed the first part, as the text is; the card has all of it.
|
|
3593
|
+
text: cut ? upTo(x.text, TERMS_TEXT_MAX) : x.text,
|
|
3594
|
+
...(cut ? { textCut: true } : {}),
|
|
3595
|
+
// ⚠️ THE MOMENT ONLY (0.63.0 screenshots): the card writes it in the viewer's own
|
|
3596
|
+
// language and time zone. "10:05 UTC, 10 Nov" here was drawn as is in a
|
|
3597
|
+
// Chinese card - and it is not the hotel's clock anyway (no zone is sent).
|
|
3598
|
+
until: x.until,
|
|
3599
|
+
...(link ? { link } : {}),
|
|
3600
|
+
},
|
|
3601
|
+
link,
|
|
3602
|
+
cut,
|
|
3603
|
+
x,
|
|
3604
|
+
};
|
|
3605
|
+
});
|
|
3606
|
+
const blocks = entries.map(({ link, x }) => {
|
|
3607
|
+
const longer = x.text.length > TERMS_TEXT_MAX;
|
|
3608
|
+
const shown = longer ? upTo(x.text, TERMS_TEXT_MAX) : x.text;
|
|
3609
|
+
const until = clockWords(x.until) ?? x.until;
|
|
3610
|
+
return [
|
|
3611
|
+
`${withZh(x.hotelName, x.hotelNames, ctx.noCards)} · ${x.roomName} · ${stayWords(x.stay)} · ${x.rooms} ${x.rooms === 1 ? 'room' : 'rooms'} · ${formatMoney(x.total)}`,
|
|
3612
|
+
`${x.groupName}'s terms, word for word:`,
|
|
3613
|
+
shown,
|
|
3614
|
+
longer
|
|
3615
|
+
? `(That is the first ${TERMS_TEXT_MAX} of ${x.text.length} characters; the whole text is ${ctx.noCards ? 'on the page' : 'on the card'}.)`
|
|
3616
|
+
: '',
|
|
3617
|
+
`They can be agreed to until ${until}.`,
|
|
3618
|
+
ctx.noCards
|
|
3619
|
+
? link
|
|
3620
|
+
? `Give the guest this one-time link to read the terms and agree on ${deps.vocab.brand}'s page - it opens only in the browser signed in to their ${deps.vocab.brand} account, works once, until ${clockWords(link.expiresAt) ?? link.expiresAt}: ${link.url}. When they say they are done, call ${t.listBookings} to see the booking and its payment page.`
|
|
3621
|
+
: 'These terms can only be agreed to on a client that shows the card; nothing was ordered.'
|
|
3622
|
+
: '',
|
|
3623
|
+
]
|
|
3624
|
+
.filter(Boolean)
|
|
3625
|
+
.join('\n');
|
|
3626
|
+
});
|
|
3627
|
+
return {
|
|
3628
|
+
structured: { terms: entries.map((e) => e.entry), termsSaid },
|
|
3629
|
+
text: [
|
|
3630
|
+
termsSaid,
|
|
3631
|
+
...blocks,
|
|
3632
|
+
ctx.noCards ? '' : 'The card shows them word for word with Agree and continue.',
|
|
3633
|
+
]
|
|
3634
|
+
.filter(Boolean)
|
|
3635
|
+
.join('\n\n'),
|
|
3636
|
+
};
|
|
3637
|
+
};
|
|
3276
3638
|
const bookingLine = (deps, b, noCards) => {
|
|
3277
3639
|
const kinds = b.requests?.kinds ?? [];
|
|
3278
3640
|
const held = noCards ? heldRoomsWords(b) : '';
|
|
@@ -3297,7 +3659,12 @@ const bookingLine = (deps, b, noCards) => {
|
|
|
3297
3659
|
: ''}`
|
|
3298
3660
|
: '',
|
|
3299
3661
|
b.payment
|
|
3300
|
-
?
|
|
3662
|
+
? // ⚠️ THE PAGE BY ITS HOST, NOT "THE CARD PAGE" (0.63.0 transcript): beside a
|
|
3663
|
+
// host the old words read "to be paid on the card page - pay on <host>", and a
|
|
3664
|
+
// client with no card reads "card page" as the booking card's.
|
|
3665
|
+
b.payment.status === 'awaiting' && b.payment.url
|
|
3666
|
+
? ` · to be paid on ${hostOf(b.payment.url) ?? 'its payment page'}${payByWords(b.payment) ? ` by ${payByWords(b.payment)}` : ''}: ${b.payment.url}`
|
|
3667
|
+
: ` · ${paymentWords(b)}`
|
|
3301
3668
|
: '',
|
|
3302
3669
|
].join('');
|
|
3303
3670
|
};
|
|
@@ -4199,6 +4566,59 @@ export const tripGone = (deps) => {
|
|
|
4199
4566
|
text: detail,
|
|
4200
4567
|
};
|
|
4201
4568
|
};
|
|
4569
|
+
/**
|
|
4570
|
+
* The guest's agreement to the terms behind `ref`, and what it came to: the
|
|
4571
|
+
* booking (with its payment page), the group's terms again, or a refusal's
|
|
4572
|
+
* code. THE ONE AGREE STEP: the booking card's own tool (`acceptTerms`) and the
|
|
4573
|
+
* one-time page (account/index.ts, `makeAccount({ terms })`) both end here, and
|
|
4574
|
+
* neither is the model's. Throws the group's refusals (`terms-gone`, `sign-in` …)
|
|
4575
|
+
* as `otaless/booking.ts` raises them: `refusalAnswer` says each.
|
|
4576
|
+
*/
|
|
4577
|
+
export const agreeToTerms = async (deps, key, ref, ctx,
|
|
4578
|
+
/** The card's own arguments (a coupon, a request to remember), as it sent them; the page has none. */
|
|
4579
|
+
args = {}) => {
|
|
4580
|
+
const t = deps.tools;
|
|
4581
|
+
const ot = deps.backend.otalessBooking;
|
|
4582
|
+
if (!ot)
|
|
4583
|
+
return {
|
|
4584
|
+
structured: { view: 'error', ...common(deps, key), error: 'not-offered' },
|
|
4585
|
+
text: `Booking terms are not agreed to through ${deps.vocab.brand}.`,
|
|
4586
|
+
isError: true,
|
|
4587
|
+
};
|
|
4588
|
+
const who = identity(deps, ctx, key);
|
|
4589
|
+
const result = await ot.acceptTerms(ref, who);
|
|
4590
|
+
const inTrip = deps.trips.read(key);
|
|
4591
|
+
const answered = await bookingAnswer(deps, t, ctx, key, key, args, inTrip, inTrip, deps.trips.shown(key), result, undefined, [], true);
|
|
4592
|
+
// The picked room's slot, when the stay was booked from there: the same stays leave it.
|
|
4593
|
+
const slot = pickedKey(key);
|
|
4594
|
+
const picked = deps.trips.read(slot);
|
|
4595
|
+
if (picked.length && result.booked.length) {
|
|
4596
|
+
const gone = (l) => result.booked.some((b) => inFailedStay(l, b));
|
|
4597
|
+
if (picked.every(gone))
|
|
4598
|
+
deps.trips.clear(slot);
|
|
4599
|
+
else
|
|
4600
|
+
for (const l of picked)
|
|
4601
|
+
if (gone(l))
|
|
4602
|
+
deps.trips.set(slot, unset(l));
|
|
4603
|
+
}
|
|
4604
|
+
return answered;
|
|
4605
|
+
};
|
|
4606
|
+
/**
|
|
4607
|
+
* The conversation's tool context and identity from its key alone - for the
|
|
4608
|
+
* one-time terms page, which has the key (account layer) and no session id. The
|
|
4609
|
+
* key is `tripKey(session, brand)`; the identity is the same one the tools build.
|
|
4610
|
+
*/
|
|
4611
|
+
export const contextFor = (deps, key) => {
|
|
4612
|
+
const suffix = ` ${deps.vocab.brand.toLowerCase()}`;
|
|
4613
|
+
return {
|
|
4614
|
+
session: key.endsWith(suffix) ? key.slice(0, -suffix.length) : key,
|
|
4615
|
+
tripKey: key,
|
|
4616
|
+
noCards: true,
|
|
4617
|
+
};
|
|
4618
|
+
};
|
|
4619
|
+
export const identityFor = (deps, key) => identity(deps, contextFor(deps, key), key);
|
|
4620
|
+
/** A booking refusal as its answer (`view: 'error'`, its code), or undefined when `err` is not one. */
|
|
4621
|
+
export const bookingRefusal = refusalAnswer;
|
|
4202
4622
|
export const handleTool = async (deps, name, rawArgs, ctx) => {
|
|
4203
4623
|
const { result, written } = await keepingAmounts(async () => {
|
|
4204
4624
|
// ⚠️ A GROUP THAT DID NOT ANSWER A READ IS AN ANSWER, NOT A FAULT (2026-11-03
|
|
@@ -4207,6 +4627,11 @@ export const handleTool = async (deps, name, rawArgs, ctx) => {
|
|
|
4207
4627
|
// connector could not answer that" - or, for a search where every group was
|
|
4208
4628
|
// silent, as the first group's name alone. Said here, naming every group.
|
|
4209
4629
|
const answer = await answerTool(deps, name, rawArgs, ctx).catch((err) => {
|
|
4630
|
+
// The group's checkout's refusals, from any tool that can get one (a
|
|
4631
|
+
// booking list, a cancellation, a refund, an add-on): answered with their code.
|
|
4632
|
+
const refused = refusalAnswer(deps, ctx.tripKey ?? tripKey(ctx.session, deps.vocab.brand), err);
|
|
4633
|
+
if (refused)
|
|
4634
|
+
return refused;
|
|
4210
4635
|
const down = unansweredBy(err);
|
|
4211
4636
|
if (!down)
|
|
4212
4637
|
throw err;
|
|
@@ -5097,6 +5522,252 @@ const putRoomLine = async (deps, t, ctx, key, store, args, detail) => {
|
|
|
5097
5522
|
? { ...now, structured: { ...now.structured, took }, text: `${took}\n${now.text}` }
|
|
5098
5523
|
: now;
|
|
5099
5524
|
};
|
|
5525
|
+
/**
|
|
5526
|
+
* What a booking asked for came to, said: the stays booked, those that were not
|
|
5527
|
+
* and why, and any terms a group sent back for the guest to agree to - for
|
|
5528
|
+
* request_booking, for the picked room's booking, and for the card's agreement
|
|
5529
|
+
* to terms (`fromTerms`: only the stays that agreement booked leave the trip).
|
|
5530
|
+
*/
|
|
5531
|
+
const bookingAnswer = async (deps, t, ctx, key, store, args, inTrip, lines, shown, result, requests, dropped, fromTerms = false) => {
|
|
5532
|
+
const { booked: made, failed, repeat, reused } = result;
|
|
5533
|
+
// Terms a group sent back: the stay waits for the guest's own agreement.
|
|
5534
|
+
const pendingTerms = result.terms ?? [];
|
|
5535
|
+
// A coupon spent is spent on the member's badge too.
|
|
5536
|
+
await refreshMember(deps, key);
|
|
5537
|
+
// ⚠️ WHAT WAS BOOKED LEAVES THE TRIP; WHAT WAS NOT STAYS IN IT, add-ons
|
|
5538
|
+
// and all - to ask again, or to put another hotel in its place (robin,
|
|
5539
|
+
// 2026-10-14).
|
|
5540
|
+
//
|
|
5541
|
+
// ⚠️ AND A STAY WITH TERMS WAITING IS NEITHER: it stays in the trip until the
|
|
5542
|
+
// guest has agreed and it is booked (then `fromTerms` takes out exactly the
|
|
5543
|
+
// stays that agreement booked, and leaves every other line where it is).
|
|
5544
|
+
const stillOut = (l) => fromTerms
|
|
5545
|
+
? !made.some((b) => inFailedStay(l, b))
|
|
5546
|
+
: failed.some((f) => inFailedStay(l, f)) || pendingTerms.some((x) => inFailedStay(l, x));
|
|
5547
|
+
if (lines.length === inTrip.length && !lines.some(stillOut))
|
|
5548
|
+
deps.trips.clear(store);
|
|
5549
|
+
else
|
|
5550
|
+
for (const l of lines)
|
|
5551
|
+
if (!stillOut(l))
|
|
5552
|
+
deps.trips.set(store, unset(l));
|
|
5553
|
+
// What is left is priced again, and that price is what the next
|
|
5554
|
+
// booking is held to (ShownQuote).
|
|
5555
|
+
const rest = fromTerms
|
|
5556
|
+
? lines.some(stillOut)
|
|
5557
|
+
? await currentTrip(deps, key, identity(deps, ctx, key), store, undefined, ctx)
|
|
5558
|
+
: undefined
|
|
5559
|
+
: lines.length === inTrip.length && !failed.length
|
|
5560
|
+
? undefined
|
|
5561
|
+
: await currentTrip(deps, key, identity(deps, ctx, key), store, undefined, ctx);
|
|
5562
|
+
const others = rest && (fromTerms || lines.length !== inTrip.length);
|
|
5563
|
+
// What could be booked instead of each, found now (robin, 2026-10-14).
|
|
5564
|
+
const instead = await Promise.all(failed.map((f, i) => i < MAX_FAILED_WITH_ALTERNATIVES
|
|
5565
|
+
? alternativesFor(deps, f, lines, shown, identity(deps, ctx, key))
|
|
5566
|
+
: Promise.resolve({ hotels: [] })));
|
|
5567
|
+
// ⚠️ REMEMBERED ONLY WHEN ASKED - see `rememberPreferences`. Said either
|
|
5568
|
+
// way, so neither the guest nor the model assumes something was kept.
|
|
5569
|
+
const signedIn = deps.members.read(key);
|
|
5570
|
+
let remembered;
|
|
5571
|
+
if (args.rememberRequests === true) {
|
|
5572
|
+
const lasting = (requests?.kinds ?? []).filter((k) => LASTING_REQUESTS.includes(k));
|
|
5573
|
+
if (!signedIn) {
|
|
5574
|
+
remembered = {
|
|
5575
|
+
kept: [],
|
|
5576
|
+
line: 'Nothing was remembered: saved preferences belong to a membership, and nobody is signed in.',
|
|
5577
|
+
};
|
|
5578
|
+
}
|
|
5579
|
+
else if (!lasting.length) {
|
|
5580
|
+
remembered = {
|
|
5581
|
+
kept: signedIn.preferences ?? [],
|
|
5582
|
+
line: 'Nothing new was remembered: an early check-in, a late arrival and a note are for one stay, not every stay.',
|
|
5583
|
+
};
|
|
5584
|
+
}
|
|
5585
|
+
else {
|
|
5586
|
+
// ADDED TO what is kept, not in place of it: a quiet room remembered
|
|
5587
|
+
// this time silently dropped the king bed remembered last time. A new
|
|
5588
|
+
// request does replace its opposite - twin beds over a king bed.
|
|
5589
|
+
const clash = (k) => lasting.some((n) => OPPOSITES.some((pair) => pair.includes(n) && pair.includes(k)));
|
|
5590
|
+
const merged = [
|
|
5591
|
+
...(signedIn.preferences ?? []).filter((k) => !lasting.includes(k) && !clash(k)),
|
|
5592
|
+
...lasting,
|
|
5593
|
+
];
|
|
5594
|
+
const kept = await deps.backend.rememberPreferences(signedIn, merged);
|
|
5595
|
+
deps.members.set(key, { ...signedIn, preferences: kept });
|
|
5596
|
+
deps.members.setPreferences(signedIn.number, kept);
|
|
5597
|
+
remembered = {
|
|
5598
|
+
kept,
|
|
5599
|
+
line: `Remembered on this ${signedIn.programme} membership for next time: ${kept.map((k) => REQUEST_WORDS[k]).join(', ')}. ${t.forgetPreferences} forgets them.`,
|
|
5600
|
+
};
|
|
5601
|
+
}
|
|
5602
|
+
}
|
|
5603
|
+
// The hotel's own check-in hour, so an early-check-in request is answered
|
|
5604
|
+
// with the time it is early against - London opens at 16:00 and Hong Kong
|
|
5605
|
+
// at 15:00, and a generic "check-in is in the afternoon" is not an answer.
|
|
5606
|
+
// Per booking: each is its own hotel, with its own hour and its own desk.
|
|
5607
|
+
const booked = await Promise.all(made.map(async (booking, i) => {
|
|
5608
|
+
// ⚠️ THE BOOKING IS MADE: a read after it that fails (a group slow to
|
|
5609
|
+
// answer) loses the check-in hour, never the answer.
|
|
5610
|
+
const hotel = await deps.backend.getHotel(booking.hotelId).catch(() => null);
|
|
5611
|
+
return {
|
|
5612
|
+
booking,
|
|
5613
|
+
// The requests that could not both be asked for are said once.
|
|
5614
|
+
asked: requestLines(booking, i === 0 ? dropped : [], hotel?.hotel.checkInFrom),
|
|
5615
|
+
};
|
|
5616
|
+
}));
|
|
5617
|
+
const [first] = booked;
|
|
5618
|
+
const several = booked.length > 1;
|
|
5619
|
+
// The stays asked for minutes before, beside new ones - see `reused`.
|
|
5620
|
+
const earlier = booked.filter(({ booking }) => reused?.includes(booking.id));
|
|
5621
|
+
// The coupon asked for, when the stays asked for before did not carry it
|
|
5622
|
+
// and nothing new did either - see `couponNotUsedOf`.
|
|
5623
|
+
const askedCoupon = couponOf(deps, args);
|
|
5624
|
+
const notUsed = couponNotUsedOf(deps, key, askedCoupon, repeat ? made : earlier.map(({ booking }) => booking), made);
|
|
5625
|
+
const waiting = booked.filter(({ booking }) => confirming(deps, booking)).length;
|
|
5626
|
+
const notBooked = failed.map((f, i) => ({
|
|
5627
|
+
hotelId: f.hotelId,
|
|
5628
|
+
hotelName: f.hotelName,
|
|
5629
|
+
stay: f.stay,
|
|
5630
|
+
...(f.hourly ? { hourly: f.hourly } : {}),
|
|
5631
|
+
...(f.roomName ? { roomName: f.roomName } : {}),
|
|
5632
|
+
rooms: roomsIn(lines, f),
|
|
5633
|
+
// What to take out of the trip to put another hotel in its place.
|
|
5634
|
+
roomRefs: lines.flatMap((l) => (l.kind === 'room' && inFailedStay(l, f) ? [l.roomId] : [])),
|
|
5635
|
+
extraRefs: lines.flatMap((l) => (l.kind === 'extra' && inFailedStay(l, f) ? [l.extraId] : [])),
|
|
5636
|
+
why: f.why,
|
|
5637
|
+
...(f.code ? { code: f.code } : {}),
|
|
5638
|
+
...(f.args ? { args: f.args } : {}),
|
|
5639
|
+
...(instead[i]?.city ? { city: instead[i]?.city } : {}),
|
|
5640
|
+
alternatives: (instead[i]?.hotels ?? []).map((h) => ({
|
|
5641
|
+
hotelId: h.id,
|
|
5642
|
+
name: h.name,
|
|
5643
|
+
brand: h.brand,
|
|
5644
|
+
...(h.forStay
|
|
5645
|
+
? {
|
|
5646
|
+
total: formatMoney(h.forStay.total),
|
|
5647
|
+
room: h.forStay.room,
|
|
5648
|
+
...(h.forStay.roomNames ? { roomNames: h.forStay.roomNames } : {}),
|
|
5649
|
+
freeCancellation: h.forStay.freeCancellation,
|
|
5650
|
+
}
|
|
5651
|
+
: {}),
|
|
5652
|
+
})),
|
|
5653
|
+
}));
|
|
5654
|
+
const failedText = notBooked.map((f) => `NOT BOOKED - ${f.hotelName} · ${stayWords(f.stay, f.hourly)}: ${f.why} It is still in the trip.${f.alternatives.length
|
|
5655
|
+
? ` Bookable instead for the same nights: ${f.alternatives.map((a) => `${a.name}${a.room ? ` (${a.room}` : ''}${a.total ? `${a.room ? ', ' : ' ('}${a.total} for the stay)` : a.room ? ')' : ''} [hotel \`${a.hotelId}\`]`).join('; ')}.`
|
|
5656
|
+
: ''} The guest can ask again, take another hotel, or leave it.`);
|
|
5657
|
+
// Terms waiting for the guest, said first: that is what needs doing.
|
|
5658
|
+
const termsPart = pendingTerms.length ? termsAnswer(deps, ctx, key, pendingTerms) : undefined;
|
|
5659
|
+
if (!first) {
|
|
5660
|
+
if (termsPart)
|
|
5661
|
+
return {
|
|
5662
|
+
structured: {
|
|
5663
|
+
view: 'terms',
|
|
5664
|
+
...common(deps, key),
|
|
5665
|
+
paid: false,
|
|
5666
|
+
...(notBooked.length ? { failed: notBooked } : {}),
|
|
5667
|
+
...termsPart.structured,
|
|
5668
|
+
},
|
|
5669
|
+
text: [termsPart.text, ...failedText].join('\n'),
|
|
5670
|
+
};
|
|
5671
|
+
// Nothing booked at all: every stay said, each with its way on.
|
|
5672
|
+
return {
|
|
5673
|
+
structured: {
|
|
5674
|
+
view: 'booking',
|
|
5675
|
+
...common(deps, key),
|
|
5676
|
+
paid: false,
|
|
5677
|
+
failed: notBooked,
|
|
5678
|
+
},
|
|
5679
|
+
text: [
|
|
5680
|
+
`Nothing was booked: ${notBooked.length === 1 ? 'the stay' : `none of the ${notBooked.length} stays`} could be.`,
|
|
5681
|
+
...failedText,
|
|
5682
|
+
].join('\n'),
|
|
5683
|
+
};
|
|
5684
|
+
}
|
|
5685
|
+
const answer = {
|
|
5686
|
+
structured: {
|
|
5687
|
+
// ⚠️ 'booking' EVEN WHEN IT IS AWAITING PAYMENT: the card draws a view
|
|
5688
|
+
// only once it knows it, and the card-contract test holds every view
|
|
5689
|
+
// here to that. 香格里拉's card turns this into its own 'payment' step
|
|
5690
|
+
// (booking.status 'awaiting-payment', booking.payment) - and moves the
|
|
5691
|
+
// view with it.
|
|
5692
|
+
view: 'booking',
|
|
5693
|
+
...common(deps, key),
|
|
5694
|
+
booking: madeForCard(deps, first.booking),
|
|
5695
|
+
// ⚠️ ONE PER STAY - see `requestBooking`. The card draws each with its
|
|
5696
|
+
// own code; `booking` stays the first, for a host that reads one.
|
|
5697
|
+
...(several
|
|
5698
|
+
? {
|
|
5699
|
+
bookings: booked.map(({ booking, asked }) => ({
|
|
5700
|
+
...madeForCard(deps, booking),
|
|
5701
|
+
total: formatMoney(booking.quote.total),
|
|
5702
|
+
...(asked.length ? { requested: asked } : {}),
|
|
5703
|
+
// Each its own warning colour - it rode on the first alone.
|
|
5704
|
+
...(booking.requests?.kinds.includes('accessible-room')
|
|
5705
|
+
? { accessibility: true }
|
|
5706
|
+
: {}),
|
|
5707
|
+
})),
|
|
5708
|
+
}
|
|
5709
|
+
: {}),
|
|
5710
|
+
paid: false,
|
|
5711
|
+
...(remembered ? { remembered: remembered.kept } : {}),
|
|
5712
|
+
// What they come to together, said by the server like every figure on
|
|
5713
|
+
// the card - never added up there (r10, #15). Only in one currency.
|
|
5714
|
+
...(several &&
|
|
5715
|
+
booked.every(({ booking }) => booking.quote.total.currency === first.booking.quote.total.currency)
|
|
5716
|
+
? {
|
|
5717
|
+
totalAll: formatMoney({
|
|
5718
|
+
minor: booked.reduce((n, { booking }) => n + booking.quote.total.minor, 0),
|
|
5719
|
+
currency: first.booking.quote.total.currency,
|
|
5720
|
+
}),
|
|
5721
|
+
}
|
|
5722
|
+
: {}),
|
|
5723
|
+
holdUntil: first.booking.holdUntil,
|
|
5724
|
+
total: formatMoney(first.booking.quote.total),
|
|
5725
|
+
...(first.asked.length ? { requested: first.asked } : {}),
|
|
5726
|
+
...(first.booking.requests?.kinds.includes('accessible-room') ? { accessibility: true } : {}),
|
|
5727
|
+
...(notBooked.length ? { failed: notBooked } : {}),
|
|
5728
|
+
...(repeat ? { repeat: true } : {}),
|
|
5729
|
+
...(earlier.length ? { repeated: earlier.map(({ booking }) => booking.id) } : {}),
|
|
5730
|
+
...(notUsed ? { couponNotUsed: notUsed.structured } : {}),
|
|
5731
|
+
},
|
|
5732
|
+
text: [
|
|
5733
|
+
// ⚠️ THE SAME BOOKING ASKED FOR AGAIN IS SAID TO BE THAT, never a new
|
|
5734
|
+
// one (2026-10-27 audit, F2): it was answered as if just booked.
|
|
5735
|
+
repeat
|
|
5736
|
+
? `NOTHING NEW WAS BOOKED: the same ${booked.length > 1 ? 'stays' : 'stay'} for the same guest ${booked.length > 1 ? 'were' : 'was'} asked for a few minutes ago, and ${booked.length > 1 ? 'these are the bookings' : 'this is the booking'} made then. A booking for someone else is made under their name.`
|
|
5737
|
+
: earlier.length
|
|
5738
|
+
? `NOT ALL NEW: ${listAnd(earlier.map(({ booking }) => booking.confirmationCode || booking.hotelName))} ${earlier.length > 1 ? 'were' : 'was'} asked for a few minutes ago for the same guest and ${earlier.length > 1 ? 'are the bookings' : 'is the booking'} made then; the rest were booked now.`
|
|
5739
|
+
: '',
|
|
5740
|
+
notUsed?.said ?? '',
|
|
5741
|
+
// ⚠️ BOOKED IS CONFIRMED: a stay still being confirmed is said as
|
|
5742
|
+
// that, and not counted (总线程, 2026-10-14).
|
|
5743
|
+
notBooked.length || (booked.length > 1 && waiting)
|
|
5744
|
+
? `${booked.length - waiting} of ${booked.length + notBooked.length} stays booked${waiting ? `, ${waiting} being confirmed by the hotel - no code until it is` : ''}${notBooked.length ? `; ${notBooked.length === 1 ? 'one' : notBooked.length} could not be, said below` : ''} - what was booked stays booked.`
|
|
5745
|
+
: '',
|
|
5746
|
+
several
|
|
5747
|
+
? `${booked.length} bookings, one for each stay - each hotel keeps its own nights under its own code, and each is ${holderOf(deps, first.booking.supplier).caps.changes ? 'changed or cancelled' : 'cancelled'} on its own.`
|
|
5748
|
+
: '',
|
|
5749
|
+
...booked.flatMap(({ booking, asked }) => [
|
|
5750
|
+
`**${confirming(deps, booking) ? 'Being confirmed' : booking.confirmationCode}** · ${withZh(booking.hotelName, booking.hotelNames, ctx.noCards)} · ${stayWords(booking.stay, booking.hourly)}`,
|
|
5751
|
+
ctx.noCards ? heldRoomsWords(booking) : '',
|
|
5752
|
+
bookedLine(deps, booking),
|
|
5753
|
+
...asked,
|
|
5754
|
+
]),
|
|
5755
|
+
...failedText,
|
|
5756
|
+
remembered?.line ?? '',
|
|
5757
|
+
others ? `The trip's other stays are still in it, not booked:\n${rest?.text ?? ''}` : '',
|
|
5758
|
+
]
|
|
5759
|
+
.filter(Boolean)
|
|
5760
|
+
.join('\n'),
|
|
5761
|
+
};
|
|
5762
|
+
if (!termsPart)
|
|
5763
|
+
return answer;
|
|
5764
|
+
// Some stays booked in this call and some waiting for terms: both are said,
|
|
5765
|
+
// the terms first, and the structure is the terms' view with the bookings in it.
|
|
5766
|
+
return {
|
|
5767
|
+
structured: { ...answer.structured, view: 'terms', ...termsPart.structured },
|
|
5768
|
+
text: [termsPart.text, answer.text].join('\n\n'),
|
|
5769
|
+
};
|
|
5770
|
+
};
|
|
5100
5771
|
/**
|
|
5101
5772
|
* Books the rooms in one slot of the trip store for a named guest - THE ONE
|
|
5102
5773
|
* BOOKING CODE, for the trip (`request_booking`, `store` the trip's own key)
|
|
@@ -5177,7 +5848,7 @@ const bookTripLines = async (deps, t, ctx, key, store, args, nothingThere) => {
|
|
|
5177
5848
|
const { requests, dropped } = readRequests(args);
|
|
5178
5849
|
try {
|
|
5179
5850
|
const shown = deps.trips.shown(store);
|
|
5180
|
-
const
|
|
5851
|
+
const result = await deps.backend.requestBooking(
|
|
5181
5852
|
// The coupon the guest named, spent on the one stay it goes on - or
|
|
5182
5853
|
// nothing is booked (see `TripDraft.coupon`).
|
|
5183
5854
|
{
|
|
@@ -5198,212 +5869,7 @@ const bookTripLines = async (deps, t, ctx, key, store, args, nothingThere) => {
|
|
|
5198
5869
|
// only place an Identity is built; the guest's email still overrides,
|
|
5199
5870
|
// because a booking is found by the address it was made with.
|
|
5200
5871
|
{ ...identity(deps, ctx, key), email: guest.email }, requests);
|
|
5201
|
-
|
|
5202
|
-
await refreshMember(deps, key);
|
|
5203
|
-
// ⚠️ WHAT WAS BOOKED LEAVES THE TRIP; WHAT WAS NOT STAYS IN IT, add-ons
|
|
5204
|
-
// and all - to ask again, or to put another hotel in its place (robin,
|
|
5205
|
-
// 2026-10-14).
|
|
5206
|
-
const stillOut = (l) => failed.some((f) => inFailedStay(l, f));
|
|
5207
|
-
if (lines.length === inTrip.length && !lines.some(stillOut))
|
|
5208
|
-
deps.trips.clear(store);
|
|
5209
|
-
else
|
|
5210
|
-
for (const l of lines)
|
|
5211
|
-
if (!stillOut(l))
|
|
5212
|
-
deps.trips.set(store, unset(l));
|
|
5213
|
-
// What is left is priced again, and that price is what the next
|
|
5214
|
-
// booking is held to (ShownQuote).
|
|
5215
|
-
const rest = lines.length === inTrip.length && !failed.length
|
|
5216
|
-
? undefined
|
|
5217
|
-
: await currentTrip(deps, key, identity(deps, ctx, key), store, undefined, ctx);
|
|
5218
|
-
const others = rest && lines.length !== inTrip.length;
|
|
5219
|
-
// What could be booked instead of each, found now (robin, 2026-10-14).
|
|
5220
|
-
const instead = await Promise.all(failed.map((f, i) => i < MAX_FAILED_WITH_ALTERNATIVES
|
|
5221
|
-
? alternativesFor(deps, f, lines, shown, identity(deps, ctx, key))
|
|
5222
|
-
: Promise.resolve({ hotels: [] })));
|
|
5223
|
-
// ⚠️ REMEMBERED ONLY WHEN ASKED - see `rememberPreferences`. Said either
|
|
5224
|
-
// way, so neither the guest nor the model assumes something was kept.
|
|
5225
|
-
const signedIn = deps.members.read(key);
|
|
5226
|
-
let remembered;
|
|
5227
|
-
if (args.rememberRequests === true) {
|
|
5228
|
-
const lasting = (requests?.kinds ?? []).filter((k) => LASTING_REQUESTS.includes(k));
|
|
5229
|
-
if (!signedIn) {
|
|
5230
|
-
remembered = {
|
|
5231
|
-
kept: [],
|
|
5232
|
-
line: 'Nothing was remembered: saved preferences belong to a membership, and nobody is signed in.',
|
|
5233
|
-
};
|
|
5234
|
-
}
|
|
5235
|
-
else if (!lasting.length) {
|
|
5236
|
-
remembered = {
|
|
5237
|
-
kept: signedIn.preferences ?? [],
|
|
5238
|
-
line: 'Nothing new was remembered: an early check-in, a late arrival and a note are for one stay, not every stay.',
|
|
5239
|
-
};
|
|
5240
|
-
}
|
|
5241
|
-
else {
|
|
5242
|
-
// ADDED TO what is kept, not in place of it: a quiet room remembered
|
|
5243
|
-
// this time silently dropped the king bed remembered last time. A new
|
|
5244
|
-
// request does replace its opposite - twin beds over a king bed.
|
|
5245
|
-
const clash = (k) => lasting.some((n) => OPPOSITES.some((pair) => pair.includes(n) && pair.includes(k)));
|
|
5246
|
-
const merged = [
|
|
5247
|
-
...(signedIn.preferences ?? []).filter((k) => !lasting.includes(k) && !clash(k)),
|
|
5248
|
-
...lasting,
|
|
5249
|
-
];
|
|
5250
|
-
const kept = await deps.backend.rememberPreferences(signedIn, merged);
|
|
5251
|
-
deps.members.set(key, { ...signedIn, preferences: kept });
|
|
5252
|
-
deps.members.setPreferences(signedIn.number, kept);
|
|
5253
|
-
remembered = {
|
|
5254
|
-
kept,
|
|
5255
|
-
line: `Remembered on this ${signedIn.programme} membership for next time: ${kept.map((k) => REQUEST_WORDS[k]).join(', ')}. ${t.forgetPreferences} forgets them.`,
|
|
5256
|
-
};
|
|
5257
|
-
}
|
|
5258
|
-
}
|
|
5259
|
-
// The hotel's own check-in hour, so an early-check-in request is answered
|
|
5260
|
-
// with the time it is early against - London opens at 16:00 and Hong Kong
|
|
5261
|
-
// at 15:00, and a generic "check-in is in the afternoon" is not an answer.
|
|
5262
|
-
// Per booking: each is its own hotel, with its own hour and its own desk.
|
|
5263
|
-
const booked = await Promise.all(made.map(async (booking, i) => {
|
|
5264
|
-
// ⚠️ THE BOOKING IS MADE: a read after it that fails (a group slow to
|
|
5265
|
-
// answer) loses the check-in hour, never the answer.
|
|
5266
|
-
const hotel = await deps.backend.getHotel(booking.hotelId).catch(() => null);
|
|
5267
|
-
return {
|
|
5268
|
-
booking,
|
|
5269
|
-
// The requests that could not both be asked for are said once.
|
|
5270
|
-
asked: requestLines(booking, i === 0 ? dropped : [], hotel?.hotel.checkInFrom),
|
|
5271
|
-
};
|
|
5272
|
-
}));
|
|
5273
|
-
const [first] = booked;
|
|
5274
|
-
const several = booked.length > 1;
|
|
5275
|
-
// The stays asked for minutes before, beside new ones - see `reused`.
|
|
5276
|
-
const earlier = booked.filter(({ booking }) => reused?.includes(booking.id));
|
|
5277
|
-
// The coupon asked for, when the stays asked for before did not carry it
|
|
5278
|
-
// and nothing new did either - see `couponNotUsedOf`.
|
|
5279
|
-
const askedCoupon = couponOf(deps, args);
|
|
5280
|
-
const notUsed = couponNotUsedOf(deps, key, askedCoupon, repeat ? made : earlier.map(({ booking }) => booking), made);
|
|
5281
|
-
const waiting = booked.filter(({ booking }) => confirming(deps, booking)).length;
|
|
5282
|
-
const notBooked = failed.map((f, i) => ({
|
|
5283
|
-
hotelId: f.hotelId,
|
|
5284
|
-
hotelName: f.hotelName,
|
|
5285
|
-
stay: f.stay,
|
|
5286
|
-
...(f.hourly ? { hourly: f.hourly } : {}),
|
|
5287
|
-
...(f.roomName ? { roomName: f.roomName } : {}),
|
|
5288
|
-
rooms: roomsIn(lines, f),
|
|
5289
|
-
// What to take out of the trip to put another hotel in its place.
|
|
5290
|
-
roomRefs: lines.flatMap((l) => (l.kind === 'room' && inFailedStay(l, f) ? [l.roomId] : [])),
|
|
5291
|
-
extraRefs: lines.flatMap((l) => l.kind === 'extra' && inFailedStay(l, f) ? [l.extraId] : []),
|
|
5292
|
-
why: f.why,
|
|
5293
|
-
...(f.code ? { code: f.code } : {}),
|
|
5294
|
-
...(f.args ? { args: f.args } : {}),
|
|
5295
|
-
...(instead[i]?.city ? { city: instead[i]?.city } : {}),
|
|
5296
|
-
alternatives: (instead[i]?.hotels ?? []).map((h) => ({
|
|
5297
|
-
hotelId: h.id,
|
|
5298
|
-
name: h.name,
|
|
5299
|
-
brand: h.brand,
|
|
5300
|
-
...(h.forStay
|
|
5301
|
-
? {
|
|
5302
|
-
total: formatMoney(h.forStay.total),
|
|
5303
|
-
room: h.forStay.room,
|
|
5304
|
-
...(h.forStay.roomNames ? { roomNames: h.forStay.roomNames } : {}),
|
|
5305
|
-
freeCancellation: h.forStay.freeCancellation,
|
|
5306
|
-
}
|
|
5307
|
-
: {}),
|
|
5308
|
-
})),
|
|
5309
|
-
}));
|
|
5310
|
-
const failedText = notBooked.map((f) => `NOT BOOKED - ${f.hotelName} · ${stayWords(f.stay, f.hourly)}: ${f.why} It is still in the trip.${f.alternatives.length
|
|
5311
|
-
? ` Bookable instead for the same nights: ${f.alternatives.map((a) => `${a.name}${a.room ? ` (${a.room}` : ''}${a.total ? `${a.room ? ', ' : ' ('}${a.total} for the stay)` : a.room ? ')' : ''} [hotel \`${a.hotelId}\`]`).join('; ')}.`
|
|
5312
|
-
: ''} The guest can ask again, take another hotel, or leave it.`);
|
|
5313
|
-
if (!first) {
|
|
5314
|
-
// Nothing booked at all: every stay said, each with its way on.
|
|
5315
|
-
return {
|
|
5316
|
-
structured: {
|
|
5317
|
-
view: 'booking',
|
|
5318
|
-
...common(deps, key),
|
|
5319
|
-
paid: false,
|
|
5320
|
-
failed: notBooked,
|
|
5321
|
-
},
|
|
5322
|
-
text: [
|
|
5323
|
-
`Nothing was booked: ${notBooked.length === 1 ? 'the stay' : `none of the ${notBooked.length} stays`} could be.`,
|
|
5324
|
-
...failedText,
|
|
5325
|
-
].join('\n'),
|
|
5326
|
-
};
|
|
5327
|
-
}
|
|
5328
|
-
return {
|
|
5329
|
-
structured: {
|
|
5330
|
-
// ⚠️ 'booking' EVEN WHEN IT IS AWAITING PAYMENT: the card draws a view
|
|
5331
|
-
// only once it knows it, and the card-contract test holds every view
|
|
5332
|
-
// here to that. 香格里拉's card turns this into its own 'payment' step
|
|
5333
|
-
// (booking.status 'awaiting-payment', booking.payment) - and moves the
|
|
5334
|
-
// view with it.
|
|
5335
|
-
view: 'booking',
|
|
5336
|
-
...common(deps, key),
|
|
5337
|
-
booking: madeForCard(deps, first.booking),
|
|
5338
|
-
// ⚠️ ONE PER STAY - see `requestBooking`. The card draws each with its
|
|
5339
|
-
// own code; `booking` stays the first, for a host that reads one.
|
|
5340
|
-
...(several
|
|
5341
|
-
? {
|
|
5342
|
-
bookings: booked.map(({ booking, asked }) => ({
|
|
5343
|
-
...madeForCard(deps, booking),
|
|
5344
|
-
total: formatMoney(booking.quote.total),
|
|
5345
|
-
...(asked.length ? { requested: asked } : {}),
|
|
5346
|
-
// Each its own warning colour - it rode on the first alone.
|
|
5347
|
-
...(booking.requests?.kinds.includes('accessible-room')
|
|
5348
|
-
? { accessibility: true }
|
|
5349
|
-
: {}),
|
|
5350
|
-
})),
|
|
5351
|
-
}
|
|
5352
|
-
: {}),
|
|
5353
|
-
paid: false,
|
|
5354
|
-
...(remembered ? { remembered: remembered.kept } : {}),
|
|
5355
|
-
// What they come to together, said by the server like every figure on
|
|
5356
|
-
// the card - never added up there (r10, #15). Only in one currency.
|
|
5357
|
-
...(several &&
|
|
5358
|
-
booked.every(({ booking }) => booking.quote.total.currency === first.booking.quote.total.currency)
|
|
5359
|
-
? {
|
|
5360
|
-
totalAll: formatMoney({
|
|
5361
|
-
minor: booked.reduce((n, { booking }) => n + booking.quote.total.minor, 0),
|
|
5362
|
-
currency: first.booking.quote.total.currency,
|
|
5363
|
-
}),
|
|
5364
|
-
}
|
|
5365
|
-
: {}),
|
|
5366
|
-
holdUntil: first.booking.holdUntil,
|
|
5367
|
-
total: formatMoney(first.booking.quote.total),
|
|
5368
|
-
...(first.asked.length ? { requested: first.asked } : {}),
|
|
5369
|
-
...(first.booking.requests?.kinds.includes('accessible-room')
|
|
5370
|
-
? { accessibility: true }
|
|
5371
|
-
: {}),
|
|
5372
|
-
...(notBooked.length ? { failed: notBooked } : {}),
|
|
5373
|
-
...(repeat ? { repeat: true } : {}),
|
|
5374
|
-
...(earlier.length ? { repeated: earlier.map(({ booking }) => booking.id) } : {}),
|
|
5375
|
-
...(notUsed ? { couponNotUsed: notUsed.structured } : {}),
|
|
5376
|
-
},
|
|
5377
|
-
text: [
|
|
5378
|
-
// ⚠️ THE SAME BOOKING ASKED FOR AGAIN IS SAID TO BE THAT, never a new
|
|
5379
|
-
// one (2026-10-27 audit, F2): it was answered as if just booked.
|
|
5380
|
-
repeat
|
|
5381
|
-
? `NOTHING NEW WAS BOOKED: the same ${booked.length > 1 ? 'stays' : 'stay'} for the same guest ${booked.length > 1 ? 'were' : 'was'} asked for a few minutes ago, and ${booked.length > 1 ? 'these are the bookings' : 'this is the booking'} made then. A booking for someone else is made under their name.`
|
|
5382
|
-
: earlier.length
|
|
5383
|
-
? `NOT ALL NEW: ${listAnd(earlier.map(({ booking }) => booking.confirmationCode || booking.hotelName))} ${earlier.length > 1 ? 'were' : 'was'} asked for a few minutes ago for the same guest and ${earlier.length > 1 ? 'are the bookings' : 'is the booking'} made then; the rest were booked now.`
|
|
5384
|
-
: '',
|
|
5385
|
-
notUsed?.said ?? '',
|
|
5386
|
-
// ⚠️ BOOKED IS CONFIRMED: a stay still being confirmed is said as
|
|
5387
|
-
// that, and not counted (总线程, 2026-10-14).
|
|
5388
|
-
notBooked.length || (booked.length > 1 && waiting)
|
|
5389
|
-
? `${booked.length - waiting} of ${booked.length + notBooked.length} stays booked${waiting ? `, ${waiting} being confirmed by the hotel - no code until it is` : ''}${notBooked.length ? `; ${notBooked.length === 1 ? 'one' : notBooked.length} could not be, said below` : ''} - what was booked stays booked.`
|
|
5390
|
-
: '',
|
|
5391
|
-
several
|
|
5392
|
-
? `${booked.length} bookings, one for each stay - each hotel keeps its own nights under its own code, and each is ${holderOf(deps, first.booking.supplier).caps.changes ? 'changed or cancelled' : 'cancelled'} on its own.`
|
|
5393
|
-
: '',
|
|
5394
|
-
...booked.flatMap(({ booking, asked }) => [
|
|
5395
|
-
`**${confirming(deps, booking) ? 'Being confirmed' : booking.confirmationCode}** · ${withZh(booking.hotelName, booking.hotelNames, ctx.noCards)} · ${stayWords(booking.stay, booking.hourly)}`,
|
|
5396
|
-
ctx.noCards ? heldRoomsWords(booking) : '',
|
|
5397
|
-
bookedLine(deps, booking),
|
|
5398
|
-
...asked,
|
|
5399
|
-
]),
|
|
5400
|
-
...failedText,
|
|
5401
|
-
remembered?.line ?? '',
|
|
5402
|
-
others ? `The trip's other stays are still in it, not booked:\n${rest?.text ?? ''}` : '',
|
|
5403
|
-
]
|
|
5404
|
-
.filter(Boolean)
|
|
5405
|
-
.join('\n'),
|
|
5406
|
-
};
|
|
5872
|
+
return await bookingAnswer(deps, t, ctx, key, store, args, inTrip, lines, shown, result, requests, dropped);
|
|
5407
5873
|
}
|
|
5408
5874
|
catch (err) {
|
|
5409
5875
|
const words = guestWords(err, BOOKING_FAULT);
|
|
@@ -5412,7 +5878,13 @@ const bookTripLines = async (deps, t, ctx, key, store, args, nothingThere) => {
|
|
|
5412
5878
|
// has seen, and what a second ask books.
|
|
5413
5879
|
if (err.code === 'price-changed') {
|
|
5414
5880
|
const again = await currentTrip(deps, key, identity(deps, ctx, key), store, undefined, ctx);
|
|
5415
|
-
|
|
5881
|
+
// ⚠️ THE CODE REACHES THE CARD (`notBooked`, as the coupon's does): the trip is
|
|
5882
|
+
// drawn again at today's price, and the card says why nothing was booked.
|
|
5883
|
+
return {
|
|
5884
|
+
...again,
|
|
5885
|
+
structured: { ...again.structured, notBooked: 'price-changed' },
|
|
5886
|
+
text: [words, again.text].join('\n\n'),
|
|
5887
|
+
};
|
|
5416
5888
|
}
|
|
5417
5889
|
// The coupon asked for cannot be used: nothing was booked, and the trip
|
|
5418
5890
|
// is shown again with it refused and why - the guest decides what next.
|
|
@@ -5438,6 +5910,11 @@ const bookTripLines = async (deps, t, ctx, key, store, args, nothingThere) => {
|
|
|
5438
5910
|
].join('\n\n'),
|
|
5439
5911
|
};
|
|
5440
5912
|
}
|
|
5913
|
+
// The group's checkout's own refusals - signed out, a guest detail missing,
|
|
5914
|
+
// terms gone - each with its own code (`BOOKING_REFUSALS`).
|
|
5915
|
+
const refused = refusalAnswer(deps, key, err);
|
|
5916
|
+
if (refused)
|
|
5917
|
+
return refused;
|
|
5441
5918
|
return {
|
|
5442
5919
|
structured: {
|
|
5443
5920
|
view: 'error',
|
|
@@ -6752,6 +7229,133 @@ const answerTool = async (deps, name, rawArgs, ctx) => {
|
|
|
6752
7229
|
}
|
|
6753
7230
|
return direct(await bookTripLines(deps, t, ctx, key, pickedKey(key), args, 'Nothing is picked: the guest presses Reserve on a room first.'));
|
|
6754
7231
|
}
|
|
7232
|
+
// The card's own: the guest pressed "Agree and continue" under a group's
|
|
7233
|
+
// booking terms. ⚠️ THE ONLY AGREEMENT THERE IS: no tool the model sees has a
|
|
7234
|
+
// parameter that means it, and this one is refused to a client that draws no
|
|
7235
|
+
// card (server.ts keeps it from the model of one that does). `ref` only names
|
|
7236
|
+
// the terms the card was showing - they are kept for the guest's own account,
|
|
7237
|
+
// for a few minutes, and used once.
|
|
7238
|
+
if (name === t.acceptTerms) {
|
|
7239
|
+
if (ctx.noCards)
|
|
7240
|
+
return {
|
|
7241
|
+
structured: { view: 'error', ...common(deps, key), error: 'card-only' },
|
|
7242
|
+
text: `${t.acceptTerms} is the booking card's own. Booking terms are agreed to by the guest, on the card or on the one-time page the booking answer gave - never in the chat.`,
|
|
7243
|
+
isError: true,
|
|
7244
|
+
};
|
|
7245
|
+
const ot = deps.backend.otalessBooking;
|
|
7246
|
+
if (!ot)
|
|
7247
|
+
return {
|
|
7248
|
+
structured: { view: 'error', ...common(deps, key), error: 'not-offered' },
|
|
7249
|
+
text: `Booking terms are not agreed to through ${deps.vocab.brand}.`,
|
|
7250
|
+
isError: true,
|
|
7251
|
+
};
|
|
7252
|
+
return await agreeToTerms(deps, key, str(args.ref), ctx, args);
|
|
7253
|
+
}
|
|
7254
|
+
// A paid booking's money back, in full: the guest asked, and the booking and
|
|
7255
|
+
// the amount were said back to them. Only this account's own booking is
|
|
7256
|
+
// known to the backend (`otalessBooking.refund` finds it in its own record).
|
|
7257
|
+
if (name === t.refundBooking) {
|
|
7258
|
+
const ot = deps.backend.otalessBooking;
|
|
7259
|
+
const ref = str(args.booking);
|
|
7260
|
+
const who = identity(deps, ctx, key);
|
|
7261
|
+
const booking = ot
|
|
7262
|
+
? await ot.refund(ref, who, upTo(str(args.reason), REFUND_REASON_MAX) || undefined)
|
|
7263
|
+
: null;
|
|
7264
|
+
if (!booking) {
|
|
7265
|
+
return {
|
|
7266
|
+
structured: { view: 'booking-not-found', ...common(deps, key), query: ref },
|
|
7267
|
+
text: 'No booking here matches that code. Only bookings made here by this account are known, so nothing was refunded.',
|
|
7268
|
+
};
|
|
7269
|
+
}
|
|
7270
|
+
return {
|
|
7271
|
+
structured: {
|
|
7272
|
+
view: 'booking',
|
|
7273
|
+
...common(deps, key),
|
|
7274
|
+
booking: madeForCard(deps, booking),
|
|
7275
|
+
total: formatMoney(booking.quote.total),
|
|
7276
|
+
refundAsked: true,
|
|
7277
|
+
},
|
|
7278
|
+
text: `Refund asked for ${booking.confirmationCode} · ${withZh(booking.hotelName, booking.hotelNames, ctx.noCards)} · ${stayWords(booking.stay, booking.hourly)}: ${booking.payment
|
|
7279
|
+
? `${paymentWords(booking)} (${formatMoney(booking.payment.amount)} paid).`
|
|
7280
|
+
: 'the group has taken the request.'}`,
|
|
7281
|
+
};
|
|
7282
|
+
}
|
|
7283
|
+
// What can be added to a booking after it is made, and adding one: text and
|
|
7284
|
+
// structure, no card. The id is the one the list gave - the backend checks it
|
|
7285
|
+
// was listed for this very booking a moment ago.
|
|
7286
|
+
if (name === t.listBookingAddons) {
|
|
7287
|
+
const ot = deps.backend.otalessBooking;
|
|
7288
|
+
const ref = str(args.booking);
|
|
7289
|
+
const found = ot ? await ot.addons(ref, identity(deps, ctx, key)) : null;
|
|
7290
|
+
if (!found) {
|
|
7291
|
+
return {
|
|
7292
|
+
structured: { view: 'booking-not-found', ...common(deps, key), query: ref },
|
|
7293
|
+
text: 'No booking here matches that code. Only bookings made here by this account have add-ons to list.',
|
|
7294
|
+
};
|
|
7295
|
+
}
|
|
7296
|
+
const needs = (e) => e.kind === 'transfer'
|
|
7297
|
+
? 'needs direction (arrival, departure or round_trip), flightNo, pickupTime (HH:MM) and date (YYYY-MM-DD)'
|
|
7298
|
+
: 'needs a date (YYYY-MM-DD) and a quantity, if more than one';
|
|
7299
|
+
return {
|
|
7300
|
+
structured: {
|
|
7301
|
+
view: 'booking-addons',
|
|
7302
|
+
...common(deps, key),
|
|
7303
|
+
booking: ref,
|
|
7304
|
+
addons: found.map((e) => ({
|
|
7305
|
+
id: e.id,
|
|
7306
|
+
name: e.name,
|
|
7307
|
+
kind: e.kind,
|
|
7308
|
+
description: e.description,
|
|
7309
|
+
price: formatMoney(e.price),
|
|
7310
|
+
per: e.per,
|
|
7311
|
+
needs: needs(e),
|
|
7312
|
+
})),
|
|
7313
|
+
},
|
|
7314
|
+
text: found.length
|
|
7315
|
+
? [
|
|
7316
|
+
`Add-ons for ${ref}:`,
|
|
7317
|
+
...found.map((e) => `- ${e.name} (id \`${e.id}\`) — ${formatMoney(e.price)} ${unitWords(e.per)}; ${needs(e)}${e.description ? `. ${e.description}` : ''}`),
|
|
7318
|
+
].join('\n')
|
|
7319
|
+
: `Nothing can be added to ${ref} just now.`,
|
|
7320
|
+
};
|
|
7321
|
+
}
|
|
7322
|
+
if (name === t.addBookingAddon) {
|
|
7323
|
+
const ot = deps.backend.otalessBooking;
|
|
7324
|
+
const ref = str(args.booking);
|
|
7325
|
+
const addon = str(args.addon);
|
|
7326
|
+
const direction = ['arrival', 'departure', 'round_trip'].includes(str(args.direction))
|
|
7327
|
+
? str(args.direction)
|
|
7328
|
+
: undefined;
|
|
7329
|
+
const done = ot
|
|
7330
|
+
? await ot.bookAddon(ref, addon, {
|
|
7331
|
+
...(direction ? { direction } : {}),
|
|
7332
|
+
...(str(args.flightNo) ? { flightNo: str(args.flightNo) } : {}),
|
|
7333
|
+
...(str(args.pickupTime) ? { pickupTime: str(args.pickupTime) } : {}),
|
|
7334
|
+
...(str(args.date) ? { date: str(args.date) } : {}),
|
|
7335
|
+
...(typeof args.quantity === 'number' ? { quantity: args.quantity } : {}),
|
|
7336
|
+
}, identity(deps, ctx, key))
|
|
7337
|
+
: null;
|
|
7338
|
+
if (!done) {
|
|
7339
|
+
return {
|
|
7340
|
+
structured: { view: 'booking-not-found', ...common(deps, key), query: ref },
|
|
7341
|
+
text: 'No booking here matches that code. Only bookings made here by this account can have an add-on.',
|
|
7342
|
+
};
|
|
7343
|
+
}
|
|
7344
|
+
return {
|
|
7345
|
+
structured: {
|
|
7346
|
+
view: 'booking-addon',
|
|
7347
|
+
...common(deps, key),
|
|
7348
|
+
booking: ref,
|
|
7349
|
+
addon: {
|
|
7350
|
+
id: addon,
|
|
7351
|
+
code: done.code,
|
|
7352
|
+
status: done.status,
|
|
7353
|
+
...(done.total ? { total: formatMoney(done.total) } : {}),
|
|
7354
|
+
},
|
|
7355
|
+
},
|
|
7356
|
+
text: `Added to ${ref}: add-on order ${done.code}, ${done.status || 'taken'}${done.total ? `, ${formatMoney(done.total)}` : ''}.`,
|
|
7357
|
+
};
|
|
7358
|
+
}
|
|
6755
7359
|
if (name === t.listBookings) {
|
|
6756
7360
|
const who = identity(deps, ctx, key, args);
|
|
6757
7361
|
const here = await deps.backend.listBookings(who, typeof args.limit === 'number' ? args.limit : undefined);
|
|
@@ -7089,7 +7693,8 @@ const answerTool = async (deps, name, rawArgs, ctx) => {
|
|
|
7089
7693
|
}
|
|
7090
7694
|
: {};
|
|
7091
7695
|
// Money already paid here, and what comes back: see `paidFactsOf`.
|
|
7092
|
-
|
|
7696
|
+
// ⚠️ NOT WHEN THE FEE IS NOT KNOWN: what comes back is then the group's to say.
|
|
7697
|
+
const paid = preview.feeUnknown ? undefined : paidFactsOf(booked, preview);
|
|
7093
7698
|
const asPreview = {
|
|
7094
7699
|
structured: {
|
|
7095
7700
|
view: 'cancellation-preview',
|
|
@@ -7118,7 +7723,9 @@ const answerTool = async (deps, name, rawArgs, ctx) => {
|
|
|
7118
7723
|
}
|
|
7119
7724
|
: {}),
|
|
7120
7725
|
...ownDemo,
|
|
7121
|
-
|
|
7726
|
+
// ⚠️ THE FEE IS NOT KNOWN BEFORE THE GROUP CANCELS (`feeUnknown`): the rule is
|
|
7727
|
+
// the group's own terms, and no figure - not even "up to" - is said.
|
|
7728
|
+
...(preview.feeUnknown ? { feeUnknown: true } : { fee: formatMoney(preview.fee) }),
|
|
7122
7729
|
// What the booking came to, so the fee is read against it (r10 #22).
|
|
7123
7730
|
...(booked ? { bookingTotal: formatMoney(booked.quote.total) } : {}),
|
|
7124
7731
|
// ⚠️ NO "REFUND": nothing was ever paid here - a demonstration takes no
|
|
@@ -7159,7 +7766,9 @@ const answerTool = async (deps, name, rawArgs, ctx) => {
|
|
|
7159
7766
|
: {}),
|
|
7160
7767
|
},
|
|
7161
7768
|
text: [
|
|
7162
|
-
|
|
7769
|
+
preview.feeUnknown
|
|
7770
|
+
? `Cancelling ${preview.confirmationCode}: the fee is not known until ${holderOf(deps, preview.supplier).name} cancels it - it is whatever ${holderOf(deps, preview.supplier).name} charges then, under its own terms:`
|
|
7771
|
+
: `Cancelling ${preview.confirmationCode} would cost ${formatMoney(preview.fee)}${preview.fee.minor === 0 ? ' - nothing' : ''}.`,
|
|
7163
7772
|
preview.rule,
|
|
7164
7773
|
preview.coupon
|
|
7165
7774
|
? couponBackWords(preview.coupon, formatMoney(preview.fee), false, holderOf(deps, preview.supplier).notReal)
|
|
@@ -7203,7 +7812,9 @@ const answerTool = async (deps, name, rawArgs, ctx) => {
|
|
|
7203
7812
|
// answers a cancellation with its penalty; the preview was our reading of
|
|
7204
7813
|
// the rate's terms, and where the two differ the hotel's is the one that
|
|
7205
7814
|
// will be charged.
|
|
7815
|
+
// ⚠️ AND WHERE THE FEE WAS NOT KNOWN, only what the group says it charged.
|
|
7206
7816
|
const charged = cancelled.cancellationFee ?? preview.fee;
|
|
7817
|
+
const feeUnsaid = !!preview.feeUnknown && !cancelled.cancellationFee;
|
|
7207
7818
|
const h = holderOf(deps, cancelled.supplier);
|
|
7208
7819
|
// What became of the coupon the booking used, said once and handed over in
|
|
7209
7820
|
// both: the structure's `coupon` and the text's sentence are this one string.
|
|
@@ -7234,7 +7845,7 @@ const answerTool = async (deps, name, rawArgs, ctx) => {
|
|
|
7234
7845
|
booking: bookingForCard(cancelled),
|
|
7235
7846
|
...which,
|
|
7236
7847
|
...ownDemo,
|
|
7237
|
-
fee: formatMoney(charged),
|
|
7848
|
+
...(feeUnsaid ? { feeUnknown: true } : { fee: formatMoney(charged) }),
|
|
7238
7849
|
rule: preview.rule,
|
|
7239
7850
|
cancellable: false,
|
|
7240
7851
|
...(couponNow ? { coupon: couponNow } : {}),
|
|
@@ -7242,14 +7853,16 @@ const answerTool = async (deps, name, rawArgs, ctx) => {
|
|
|
7242
7853
|
text: [
|
|
7243
7854
|
cancelled.payment
|
|
7244
7855
|
? // Paid here in advance: what becomes of the money is the answer.
|
|
7245
|
-
`${cancelled.confirmationCode} is ${cancelled.status === 'expired' ? 'called off before it was paid' : 'cancelled'}. ${paidLine(deps, cancelled, charged)}`
|
|
7246
|
-
:
|
|
7247
|
-
?
|
|
7248
|
-
|
|
7249
|
-
|
|
7250
|
-
|
|
7251
|
-
|
|
7252
|
-
:
|
|
7856
|
+
`${cancelled.confirmationCode} is ${cancelled.status === 'expired' ? 'called off before it was paid' : 'cancelled'}. ${paidLine(deps, cancelled, feeUnsaid ? undefined : charged)}`
|
|
7857
|
+
: feeUnsaid
|
|
7858
|
+
? `${cancelled.confirmationCode} is cancelled. ${h.name} charges whatever its own terms say; the amount is not known here.`
|
|
7859
|
+
: h.notReal
|
|
7860
|
+
? // The fact, in no environment's word (robin, 2026-11-03); nobody charges
|
|
7861
|
+
// a booking that was never sent anything (2026-10-05 audit, P2).
|
|
7862
|
+
`${cancelled.confirmationCode} is cancelled. ${charged.minor === 0 ? 'No fee.' : `A real booking on this rate would be charged ${formatMoney(charged)}; this booking was never sent to ${h.name}, and nothing is charged.`}`
|
|
7863
|
+
: h.test
|
|
7864
|
+
? `${cancelled.confirmationCode} is cancelled. ${charged.minor === 0 ? 'No fee.' : `A real booking on this rate would be charged ${formatMoney(charged)}; this booking held no room for anyone, and nothing is charged.`}`
|
|
7865
|
+
: `${cancelled.confirmationCode} is cancelled. ${charged.minor === 0 ? 'No fee.' : `The hotel charges ${formatMoney(charged)}.`}`,
|
|
7253
7866
|
couponNow?.said ?? '',
|
|
7254
7867
|
demoBookingNote(deps, cancelled.supplier),
|
|
7255
7868
|
]
|