@curless/hotel-storefront 0.71.1 → 0.71.3
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/ota-member.d.ts.map +1 -1
- package/dist/account/ota-member.js +4 -2
- package/dist/account/ota-member.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/otaless/backend.d.ts +2 -0
- package/dist/otaless/backend.d.ts.map +1 -1
- package/dist/otaless/backend.js +43 -4
- package/dist/otaless/backend.js.map +1 -1
- package/dist/otaless/booking.d.ts +27 -8
- package/dist/otaless/booking.d.ts.map +1 -1
- package/dist/otaless/booking.js +123 -22
- package/dist/otaless/booking.js.map +1 -1
- package/dist/otaless/client.d.ts +12 -2
- package/dist/otaless/client.d.ts.map +1 -1
- package/dist/otaless/client.js +16 -3
- package/dist/otaless/client.js.map +1 -1
- package/dist/otaless/fake.d.ts +6 -0
- package/dist/otaless/fake.d.ts.map +1 -1
- package/dist/otaless/fake.js +4 -0
- package/dist/otaless/fake.js.map +1 -1
- package/dist/otaless/make.d.ts.map +1 -1
- package/dist/otaless/make.js +7 -2
- package/dist/otaless/make.js.map +1 -1
- package/dist/server.d.ts +2 -2
- package/dist/server.js +2 -2
- package/dist/tools.d.ts.map +1 -1
- package/dist/types.d.ts +12 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/otaless/booking.js
CHANGED
|
@@ -207,13 +207,24 @@ const moneyOf = (amount, currency) => {
|
|
|
207
207
|
return undefined;
|
|
208
208
|
return money(toMinor(a, c), c);
|
|
209
209
|
};
|
|
210
|
+
/** Currencies a summary writes its amounts in, as `CNY1500` - never taken for a member's number. */
|
|
211
|
+
const CURRENCY_CODES = 'CNY|USD|EUR|JPY|SGD|HKD|GBP|MYR|AUD|THB|KRW|TWD|MOP|IDR|VND|PHP|INR|CHF|CAD|NZD|AED';
|
|
212
|
+
const MEMBER_NO = new RegExp(`\\b(?!(?:${CURRENCY_CODES})\\d)[A-Za-z]{1,4}\\d{4,}\\b`, 'g');
|
|
210
213
|
/**
|
|
211
214
|
* 8's `summary` for the log: as `forTheLog`, and a member's number (`AT437617`) and the
|
|
212
|
-
* name beside 「会员」 taken out too.
|
|
215
|
+
* name beside 「会员」 taken out too - and (0.71.2 / 0.71.3, 总线程's reviews, P3) any key
|
|
216
|
+
* or token in it, in any case and any shape: `sk_test_…` / `sk_live_…` (`pk_`, `rk_`),
|
|
217
|
+
* `whsec_…`, `Bearer …`, and whatever follows `api_key=`, `apiKey=` or `"api_key":"`, so a
|
|
218
|
+
* real one never reaches the log. An amount (`CNY1500`) is left as it is.
|
|
213
219
|
*/
|
|
214
|
-
const summaryForLog = (s, guest) => forTheLog(s
|
|
215
|
-
.replace(
|
|
216
|
-
.replace(/\
|
|
220
|
+
export const summaryForLog = (s, guest) => forTheLog(s
|
|
221
|
+
.replace(/\b(sk|pk|rk)_(test|live)_[A-Za-z0-9_]+/gi, '$1_$2_<key>')
|
|
222
|
+
.replace(/\bwhsec_[A-Za-z0-9_]+/gi, 'whsec_<key>')
|
|
223
|
+
.replace(/(Bearer\s+)[A-Za-z0-9._~+/=-]+/gi, '$1<token>')
|
|
224
|
+
.replace(/("?api_?key"?\s*[:=]\s*"?)[^"\s&,)})]+/gi, '$1<key>')
|
|
225
|
+
.replace(/会员\s*[::]?\s*[^\s((·::]+/g, '会员:<member>')
|
|
226
|
+
.replace(/(member)\s*[::]\s*[^\s((·]+/gi, '$1:<member>')
|
|
227
|
+
.replace(MEMBER_NO, '<member no>'), guest);
|
|
217
228
|
/** An amount for the log, as the backend would write it - `CNY 86.00`. Never a guest's. */
|
|
218
229
|
const amountForLog = (m) => `${m.currency} ${(m.minor / minorFactor(m.currency)).toFixed(decimalsOf(m.currency))}`;
|
|
219
230
|
const same = (a, b) => !!a && !!b && a.currency === b.currency && a.minor === b.minor;
|
|
@@ -247,6 +258,11 @@ export const pathSegments = (path) => {
|
|
|
247
258
|
* must name the order (`host/a/b?order={order}` - `order` is the parameter's
|
|
248
259
|
* name, 总线程 11-11, B). A malformed path or query matches nothing.
|
|
249
260
|
*/
|
|
261
|
+
/** A group's own payment-page token (`{token}`): letters, digits, `_` and `-`, at most this long. */
|
|
262
|
+
const PAGE_TOKEN_MAX = 64;
|
|
263
|
+
const PAGE_TOKEN = new RegExp(`^[A-Za-z0-9_-]{1,${PAGE_TOKEN_MAX}}$`);
|
|
264
|
+
/** A page's `lang`: `zh`, `en`, `zh-CN`, `zh_Hant`. */
|
|
265
|
+
const PAGE_LANG = /^[A-Za-z]{2,3}(?:[-_][A-Za-z0-9]{2,8})?$/;
|
|
250
266
|
export const checkoutEntryOf = (entry) => {
|
|
251
267
|
const e = entry.trim();
|
|
252
268
|
const q = e.indexOf('?');
|
|
@@ -254,6 +270,9 @@ export const checkoutEntryOf = (entry) => {
|
|
|
254
270
|
const slash = left.indexOf('/');
|
|
255
271
|
const host = (slash < 0 ? left : left.slice(0, slash)).toLowerCase();
|
|
256
272
|
const under = slash < 0 ? [] : (pathSegments(left.slice(slash)) ?? ['\u0000']);
|
|
273
|
+
// `host/pay/{group}/{token}` (0.71.3): the group's own page by its token - see `payPageOf`.
|
|
274
|
+
if (q < 0 && under.length >= 2 && under.at(-2) === '{group}' && under.at(-1) === '{token}')
|
|
275
|
+
return { host, under: under.slice(0, -2), tokenPage: true };
|
|
257
276
|
if (q < 0)
|
|
258
277
|
return { host, under };
|
|
259
278
|
const m = /^([A-Za-z0-9_.~-]+)=\{order\}$/.exec(e.slice(q + 1));
|
|
@@ -297,7 +316,12 @@ export const checkoutHostsProblem = (hosts) => {
|
|
|
297
316
|
* no fragment. What is handed on is rebuilt from the entry and the order, never
|
|
298
317
|
* the backend's own string. No order to hold it to: nothing.
|
|
299
318
|
*/
|
|
300
|
-
export const payPageOf = (raw, hosts,
|
|
319
|
+
export const payPageOf = (raw, hosts,
|
|
320
|
+
/**
|
|
321
|
+
* The order: its ids - and the group it was ordered at and the `providerCode` its answer
|
|
322
|
+
* gave (0.71.3), which a page through a `{group}/{token}` entry must name.
|
|
323
|
+
*/
|
|
324
|
+
order) => {
|
|
301
325
|
if (!raw)
|
|
302
326
|
return undefined;
|
|
303
327
|
let u;
|
|
@@ -317,6 +341,33 @@ export const payPageOf = (raw, hosts, order) => {
|
|
|
317
341
|
const e = checkoutEntryOf(h);
|
|
318
342
|
if (e.host !== host || !e.under.every((seg, i) => segs[i] === seg))
|
|
319
343
|
continue;
|
|
344
|
+
// ⚠️ A PAGE BY THE GROUP'S OWN TOKEN (0.71.3, robin 11-13: Atour's page on agent.curless.ai
|
|
345
|
+
// is /pay/atour/ab-a515ece66623?lang=zh - its own token, no order in it, so "the page names
|
|
346
|
+
// the order" turned every one away and the order was cancelled). Through `host/…/{group}/{token}`
|
|
347
|
+
// alone, and held to it: exactly two segments under the path - the group this order was
|
|
348
|
+
// placed at, which its answer's `providerCode` names too, and a token of letters, digits,
|
|
349
|
+
// `_` and `-`, at most `PAGE_TOKEN_MAX` - with no fragment and no query but `lang`. What is
|
|
350
|
+
// handed on is rebuilt from those, never the backend's own string.
|
|
351
|
+
if (e.tokenPage) {
|
|
352
|
+
const group = order?.group?.toLowerCase();
|
|
353
|
+
const [g, token] = segs.slice(e.under.length);
|
|
354
|
+
const lang = u.searchParams.get('lang');
|
|
355
|
+
if (!group ||
|
|
356
|
+
segs.length !== e.under.length + 2 ||
|
|
357
|
+
g !== group ||
|
|
358
|
+
(order?.provider !== undefined && order.provider.toLowerCase() !== group) ||
|
|
359
|
+
!token ||
|
|
360
|
+
!PAGE_TOKEN.test(token) ||
|
|
361
|
+
u.hash ||
|
|
362
|
+
[...u.searchParams.keys()].some((k) => k !== 'lang') ||
|
|
363
|
+
u.searchParams.getAll('lang').length > 1 ||
|
|
364
|
+
(lang !== null && !PAGE_LANG.test(lang)))
|
|
365
|
+
continue;
|
|
366
|
+
return {
|
|
367
|
+
url: `https://${host}/${[...e.under, g, token].join('/')}${lang ? `?lang=${lang}` : ''}`,
|
|
368
|
+
host,
|
|
369
|
+
};
|
|
370
|
+
}
|
|
320
371
|
if (e.order === undefined) {
|
|
321
372
|
if (!namesOrder(u, segs, order))
|
|
322
373
|
continue;
|
|
@@ -760,11 +811,16 @@ export const createOtalessBookings = (deps) => {
|
|
|
760
811
|
return { method: 'card', amount, status: 'lapsed' };
|
|
761
812
|
return undefined;
|
|
762
813
|
};
|
|
814
|
+
/**
|
|
815
|
+
* ⚠️ THE PRICE AN ORDER IS SAID AT, WHEREVER IT IS SAID (0.71.1 `atGroupAmount`; 0.71.2,
|
|
816
|
+
* 总线程's review P2-1): 8's own amount where it was handed on at it - the price the
|
|
817
|
+
* payment page asks - else the quote. The booking and the terms held back for the guest
|
|
818
|
+
* read it alike: a terms card said ¥1378 over a page that took ¥1500.
|
|
819
|
+
*/
|
|
820
|
+
const priceOf = (r) => (r.atGroupAmount && r.charged ? r.charged : r.quoted);
|
|
763
821
|
const toBooking = (r) => {
|
|
764
822
|
const n = nightsOf(r.stay.checkIn, r.stay.checkOut);
|
|
765
|
-
|
|
766
|
-
// price the payment page asks, as the backend sent it - never the quote beside it.
|
|
767
|
-
const price = r.atGroupAmount && r.charged ? r.charged : r.quoted;
|
|
823
|
+
const price = priceOf(r);
|
|
768
824
|
const line = {
|
|
769
825
|
kind: 'room',
|
|
770
826
|
hotelId: r.hotelId,
|
|
@@ -1021,7 +1077,7 @@ export const createOtalessBookings = (deps) => {
|
|
|
1021
1077
|
roomName: r.roomName,
|
|
1022
1078
|
stay: r.stay,
|
|
1023
1079
|
rooms: r.rooms,
|
|
1024
|
-
total: r
|
|
1080
|
+
total: priceOf(r),
|
|
1025
1081
|
text: shown,
|
|
1026
1082
|
source: 'booking',
|
|
1027
1083
|
more: true,
|
|
@@ -1092,7 +1148,7 @@ export const createOtalessBookings = (deps) => {
|
|
|
1092
1148
|
price: `${g} asked for a different amount than the price the guest was shown`,
|
|
1093
1149
|
amount: `${g} did not say what it would charge`,
|
|
1094
1150
|
adults: `${g} took the order for another number of guests than the guest chose`,
|
|
1095
|
-
address: `${g} sent a payment page
|
|
1151
|
+
address: `${g} sent a payment page whose address does not match this booking`,
|
|
1096
1152
|
terms: `${g} asked for terms of its own to be agreed to when it was ordered, which cannot be shown here`,
|
|
1097
1153
|
confirm: `${g} made the order asking for it to be confirmed, with nothing here the guest could confirm as they were shown it`,
|
|
1098
1154
|
'confirm-unsent': `${g} asked for the order to be confirmed first, and that confirmation cannot be sent back from here yet`,
|
|
@@ -1110,7 +1166,10 @@ export const createOtalessBookings = (deps) => {
|
|
|
1110
1166
|
? 'price-changed'
|
|
1111
1167
|
: why === 'confirm-unsent'
|
|
1112
1168
|
? 'group-confirm'
|
|
1113
|
-
: '
|
|
1169
|
+
: why === 'address'
|
|
1170
|
+
? // Its own words (0.71.3): the page did not match - never "not the one you chose".
|
|
1171
|
+
'pay-page-refused'
|
|
1172
|
+
: 'order-cancelled'),
|
|
1114
1173
|
};
|
|
1115
1174
|
// ⚠️ SAID AS IT IS: an order stands at the group that is not the one asked
|
|
1116
1175
|
// for - never "not booked". Listed, with no page to pay it on.
|
|
@@ -1325,9 +1384,13 @@ export const createOtalessBookings = (deps) => {
|
|
|
1325
1384
|
// #53, #61 (1) - 8's own example): paid is what 15 says, never this status.
|
|
1326
1385
|
const confirmed = !page && (status === 'CONFIRMED' || status === 'PAID');
|
|
1327
1386
|
const r = recordOf(a, pairs, id, code, confirmed ? 'confirmed' : 'awaiting-payment');
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1387
|
+
// ⚠️ NOTHING TO PAY IS NO AMOUNT (0.71.2, 总线程's review P2-2): the dev backend answers
|
|
1388
|
+
// 0 often enough (questions #46), and with the group's price not checked an order of
|
|
1389
|
+
// US$0 went out with its payment page. Zero or less is no amount - cancelled as one.
|
|
1390
|
+
const asked8 = moneyOf(w.totalAmount, w.currency);
|
|
1391
|
+
const charged = asked8 && asked8.minor > 0 ? asked8 : undefined;
|
|
1392
|
+
if (asked8)
|
|
1393
|
+
r.charged = asked8;
|
|
1331
1394
|
// A step the group asks for, the order made (questions #66, #68).
|
|
1332
1395
|
const step = /TERMS/.test(status) ? 'terms' : stepAsked(status);
|
|
1333
1396
|
if (step && !deps.proceedWithoutGroupConfirm) {
|
|
@@ -1345,7 +1408,7 @@ export const createOtalessBookings = (deps) => {
|
|
|
1345
1408
|
r.atGroupAmount = true;
|
|
1346
1409
|
}
|
|
1347
1410
|
else if (!charged || !(same(charged, pairs.orig) || same(charged, pairs.usd))) {
|
|
1348
|
-
log(`[otaless] booking at ${a.group} asked ${
|
|
1411
|
+
log(`[otaless] booking at ${a.group} asked ${asked8 ? `${asked8.currency} ${asked8.minor}` : 'no amount'}, quoted ${pairs.orig.currency} ${pairs.orig.minor}${pairs.usd ? ` / USD ${pairs.usd.minor}` : ''} - cancelled`);
|
|
1349
1412
|
return letGo(a, r, charged ? 'price' : 'amount');
|
|
1350
1413
|
}
|
|
1351
1414
|
// ── the guests (总线程 11-11, C - questions #62): said, it is the number quoted ──
|
|
@@ -1356,7 +1419,12 @@ export const createOtalessBookings = (deps) => {
|
|
|
1356
1419
|
}
|
|
1357
1420
|
// ── the payment page (总线程 11-10, rule 5; 11-11, B) ──
|
|
1358
1421
|
if (page) {
|
|
1359
|
-
const ok = payPageOf(page, deps.checkoutHosts, {
|
|
1422
|
+
const ok = payPageOf(page, deps.checkoutHosts, {
|
|
1423
|
+
id,
|
|
1424
|
+
code,
|
|
1425
|
+
group: a.group,
|
|
1426
|
+
...(text(w.providerCode) ? { provider: text(w.providerCode) } : {}),
|
|
1427
|
+
});
|
|
1360
1428
|
if (!ok) {
|
|
1361
1429
|
// ⚠️ ITS HOST ALONE ON THE LOG (总线程's review of 0.66.0, 4) - never its
|
|
1362
1430
|
// path or query: either may carry a payment token.
|
|
@@ -1444,9 +1512,12 @@ export const createOtalessBookings = (deps) => {
|
|
|
1444
1512
|
}
|
|
1445
1513
|
class NotPriced extends Error {
|
|
1446
1514
|
busy;
|
|
1447
|
-
|
|
1515
|
+
wait;
|
|
1516
|
+
/** `busy`: held back by a limit of ours; `wait`: the backend refused it as a repeat (10014), twice. */
|
|
1517
|
+
constructor(busy, wait = false) {
|
|
1448
1518
|
super('not priced');
|
|
1449
1519
|
this.busy = busy;
|
|
1520
|
+
this.wait = wait;
|
|
1450
1521
|
}
|
|
1451
1522
|
}
|
|
1452
1523
|
/**
|
|
@@ -1471,13 +1542,36 @@ export const createOtalessBookings = (deps) => {
|
|
|
1471
1542
|
w = await withSession(a.acct, a.who, async (cred) => {
|
|
1472
1543
|
fromBook = undefined;
|
|
1473
1544
|
let priced;
|
|
1545
|
+
const ask = (mode) => deps.quoteIn(a.hotel, a.roomId, a.stay, a.rooms, cred, a.who, mode);
|
|
1546
|
+
const notPriced = (err) => isCode(err, NOT_SIGNED_IN) || isCode(err, CHANNEL_SESSION_EXPIRED)
|
|
1547
|
+
? err
|
|
1548
|
+
: new NotPriced(err instanceof OtalessBusy, isCode(err, REPEAT_SUBMIT));
|
|
1549
|
+
// ⚠️ THE 7 IN THE GUEST'S SESSION FIRST, AS EVER (总线程's review of 0.71.2, P2): it
|
|
1550
|
+
// selects the room and the adults at the group for 8 (questions #62) - a guest who
|
|
1551
|
+
// picked A, priced B and then booked A within the half minute would otherwise be
|
|
1552
|
+
// booked on whatever the session last held. ⚠️ ONLY A 10014 TAKES THE PRICE JUST
|
|
1553
|
+
// SHOWN (0.71.2, robin's Atour order at 10:58): the same body went in a moment ago,
|
|
1554
|
+
// so the session holds this room - the same room, nights, adults and rooms, priced
|
|
1555
|
+
// under this member's own sign-in within 30 s, is the price 8 goes on. Nothing kept:
|
|
1556
|
+
// asked once more after the pause, and a second 10014 is the group's "wait a moment".
|
|
1474
1557
|
try {
|
|
1475
|
-
priced = await
|
|
1558
|
+
priced = await ask('once');
|
|
1476
1559
|
}
|
|
1477
1560
|
catch (err) {
|
|
1478
|
-
if (isCode(err,
|
|
1479
|
-
throw err;
|
|
1480
|
-
|
|
1561
|
+
if (!isCode(err, REPEAT_SUBMIT))
|
|
1562
|
+
throw notPriced(err);
|
|
1563
|
+
const shown = deps.recentQuote?.(a.hotel, a.roomId, a.stay, a.rooms, cred.token);
|
|
1564
|
+
if (shown) {
|
|
1565
|
+
priced = { data: shown };
|
|
1566
|
+
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)`);
|
|
1567
|
+
}
|
|
1568
|
+
else
|
|
1569
|
+
try {
|
|
1570
|
+
priced = await ask('after-pause');
|
|
1571
|
+
}
|
|
1572
|
+
catch (again) {
|
|
1573
|
+
throw notPriced(again);
|
|
1574
|
+
}
|
|
1481
1575
|
}
|
|
1482
1576
|
const orig = moneyOf(priced.data?.originalAmount, priced.data?.originalCurrency);
|
|
1483
1577
|
// ⚠️ THE PRICE THE GUEST SAW, TO THE CENT, OR 8 IS NOT CALLED.
|
|
@@ -1613,7 +1707,10 @@ export const createOtalessBookings = (deps) => {
|
|
|
1613
1707
|
return {
|
|
1614
1708
|
failed: err.busy
|
|
1615
1709
|
? limited(a, g.name)
|
|
1616
|
-
:
|
|
1710
|
+
: err.wait
|
|
1711
|
+
? // ⚠️ NOT "DID NOT PRICE IT" (总线程 11-13): the group asked for a moment.
|
|
1712
|
+
failedStay(a, `${g.name} asked us to wait a moment before pricing it again, so nothing was booked - the guest can press Book again in a few seconds.`, 'group-wait')
|
|
1713
|
+
: failedStay(a, `${g.name} did not price it again just now, so nothing was booked.`, 'unreachable'),
|
|
1617
1714
|
};
|
|
1618
1715
|
if (err instanceof OtalessBusy)
|
|
1619
1716
|
return { failed: limited(a, g.name) };
|
|
@@ -2174,6 +2271,8 @@ export const createOtalessBookings = (deps) => {
|
|
|
2174
2271
|
const ok = payPageOf(text(row.checkoutUrl ?? undefined), deps.checkoutHosts, {
|
|
2175
2272
|
id: r.id,
|
|
2176
2273
|
code: r.code,
|
|
2274
|
+
group: r.group,
|
|
2275
|
+
...(text(row.providerCode) ? { provider: text(row.providerCode) } : {}),
|
|
2177
2276
|
});
|
|
2178
2277
|
if (ok)
|
|
2179
2278
|
payLinks.set(r.id, ok.url);
|
|
@@ -2250,6 +2349,8 @@ export const createOtalessBookings = (deps) => {
|
|
|
2250
2349
|
const ok = payPageOf(text(row.checkoutUrl ?? undefined), deps.checkoutHosts, {
|
|
2251
2350
|
id,
|
|
2252
2351
|
code: text(row.originalOrderId),
|
|
2352
|
+
group: o.group,
|
|
2353
|
+
...(text(row.providerCode) ? { provider: text(row.providerCode) } : {}),
|
|
2253
2354
|
});
|
|
2254
2355
|
orders.delete(o.id);
|
|
2255
2356
|
o.id = id;
|