@curless/hotel-storefront 0.74.3 → 0.74.5

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, isBookingTerms, priceTaken, } from './client.js';
7
+ import { CHANNEL_SESSION_EXPIRED, NOT_SIGNED_IN, OtalessBusy, OtalessError, REPEAT_SUBMIT, SESSION_ID, forTheLog, isBookingTerms, localeAsked, priceTaken, } 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 不需要」
@@ -707,6 +707,11 @@ export const unlinkedSaid = (err) => {
707
707
  return (/(未|没有?)(绑定|关联)(该|此|这个)?(渠道|集团|会员)|(渠道|集团)(会员)?(未|没有?)(绑定|关联|登录)|未登录(该|此|这个)?渠道|请先(绑定|关联|登录)(该|此|这个)?(渠道|集团)|渠道凭据(不存在|为空|缺失)/.test(msg) ||
708
708
  /\b(channel|membership|provider)\b[^.]{0,40}\b(not (linked|bound|signed in)|unlinked|unbound)\b|\bnot (linked|bound) to\b/i.test(msg));
709
709
  };
710
+ /**
711
+ * How long a refund not sent (or not known) is said line by line, NEEDS A PERSON, each time the
712
+ * service starts - counted from its cancellation (0.74.4). Older, one line counts them.
713
+ */
714
+ export const REFUND_SAID_DAYS = 7;
710
715
  const isCode = (err, code) => err instanceof OtalessError && !(err instanceof OtalessBusy) && err.backendCode === code;
711
716
  /**
712
717
  * Sent, and no answer it could be read by: whether it was done is not known -
@@ -746,6 +751,8 @@ export const createOtalessBookings = (deps) => {
746
751
  termsSent: 0,
747
752
  termsAgreed: 0,
748
753
  sessionRetried: 0,
754
+ /** 16 refused as a repeat (10014) and asked once more after the pause (0.74.5). */
755
+ initRepeated: 0,
749
756
  /** Cancelled, and the refund the cancel asked (9.1) not taken - a person takes it up (0.74.2). */
750
757
  refundNotSent: 0,
751
758
  /** …or not answered: whether it was sent is not known (0.74.3). */
@@ -845,14 +852,18 @@ export const createOtalessBookings = (deps) => {
845
852
  sessions.delete(first);
846
853
  }
847
854
  };
848
- /** A fresh handshake (16) - with the sign-in's token, never anonymous (总线程 11-10). */
855
+ /**
856
+ * A fresh handshake (16) - with the sign-in's token, never anonymous (总线程 11-10).
857
+ *
858
+ * ⚠️ 16 REFUSED AS A REPEAT (10014) IS ASKED ONCE MORE, `QUOTE_REPEAT_PAUSE_MS` ON (0.74.5,
859
+ * robin's demo 11-17 07:36-07:47 UTC: Shangri-La's and JI's 8 answered 4012, the handshake
860
+ * right after it 10014 - the one before 8 had gone in a moment earlier - and the booking was
861
+ * only "not taken"). As a 7 is: past the backend's `@RepeatSubmit` window. A handshake orders
862
+ * nothing. Once only: a second 10014 is thrown as it came.
863
+ */
849
864
  const handshake = async (acct, who) => {
850
865
  const group = acct.group;
851
- let sent;
852
- try {
853
- sent = await client.initialize(group, { token: acct.token }, deps.callerOf(who));
854
- }
855
- catch (err) {
866
+ const refused = (err) => {
856
867
  if (err instanceof OtalessError &&
857
868
  !(err instanceof OtalessBusy) &&
858
869
  err.backendCode !== undefined) {
@@ -863,10 +874,26 @@ export const createOtalessBookings = (deps) => {
863
874
  // 0.74.1 (总线程's review of 0.74.0, P3): the account's sign-in over is said as that -
864
875
  // and the group not linked as that - never as the group not taking the booking.
865
876
  if (isCode(err, NOT_SIGNED_IN))
866
- throw signedOut(acct);
877
+ return signedOut(acct);
867
878
  if (unlinkedSaid(err))
868
- throw linkFirst(acct, 'initialize said so in its own words');
869
- throw err;
879
+ return linkFirst(acct, 'initialize said so in its own words');
880
+ return err;
881
+ };
882
+ let sent;
883
+ try {
884
+ sent = await client.initialize(group, { token: acct.token }, deps.callerOf(who));
885
+ }
886
+ catch (err) {
887
+ if (!isCode(err, REPEAT_SUBMIT))
888
+ throw refused(err);
889
+ counts.initRepeated += 1;
890
+ log(`[otaless] initialize for ${group} answered 10014 (a handshake a moment ago) - asked once more after the pause`);
891
+ try {
892
+ sent = await client.initialize(group, { token: acct.token }, deps.callerOf(who), 'after-pause');
893
+ }
894
+ catch (again) {
895
+ throw refused(again);
896
+ }
870
897
  }
871
898
  const id = text(sent.data?.mcpSessionId) ?? sent.session;
872
899
  if (sent.data?.success === false || !id || !SESSION_ID.test(id)) {
@@ -915,7 +942,26 @@ export const createOtalessBookings = (deps) => {
915
942
  }
916
943
  counts.sessionRetried += 1;
917
944
  sessions.delete(sessionKey(acct));
918
- const again = await handshake(acct, who);
945
+ let again;
946
+ try {
947
+ again = await handshake(acct, who);
948
+ }
949
+ catch (err) {
950
+ // ⚠️ 4012, AND NO NEW SESSION (0.74.5, robin's demo 11-17): the 4012 stands - "Channel
951
+ // session expired for [shangrila]. Please re-login to this channel" - so the guest is
952
+ // asked to link that group (`linkFirst`), never told only that it was not booked. The
953
+ // 4012 is answered before the group is asked (the document's
954
+ // `requireMemberAndMcpSession`): nothing was ordered. A 401 (the account's own sign-in)
955
+ // and a group's own words for not linked are already said as those (`handshake`).
956
+ if (!(err instanceof OtalessError))
957
+ throw err;
958
+ const how = err instanceof OtalessBusy
959
+ ? 'was held back by a limit of ours'
960
+ : err.backendCode !== undefined
961
+ ? `was refused (code ${err.backendCode})`
962
+ : 'was not answered or gave no session';
963
+ throw linkFirst(acct, `4012, and the new handshake ${how}`);
964
+ }
919
965
  try {
920
966
  const r = await call({ token: acct.token, session: again });
921
967
  if (r.session && r.session !== again)
@@ -1483,17 +1529,41 @@ export const createOtalessBookings = (deps) => {
1483
1529
  holdFor(r);
1484
1530
  // ⚠️ A REFUND NOT SENT IS SAID AGAIN WHEN THE SERVICE STARTS (0.74.3, 总线程's review of 0.74.2,
1485
1531
  // P3) - and one a restart cut short (`asking` kept) is one nobody knows the fate of: `unsure`.
1532
+ // ⚠️ …BUT NOT ON EVERY START FOREVER (0.74.4, 总线程's review of 0.74.3, P3: the same lines on
1533
+ // each restart drown the new ones). One a person has taken up (`refund.handledAt`) is not said
1534
+ // again; one cancelled more than `REFUND_SAID_DAYS` ago is not said line by line - one line
1535
+ // counts them, without NEEDS A PERSON (each had its own when it happened, and on each start
1536
+ // since). A refund a restart cut short is news, and said whenever it was cancelled.
1537
+ const saidSince = now() - REFUND_SAID_DAYS * 86_400_000;
1538
+ const older = [];
1486
1539
  for (const r of [...orders.values()]) {
1487
1540
  const f = r.refund;
1488
1541
  if (!f || (f.status !== 'not-sent' && f.status !== 'unsure'))
1489
1542
  continue;
1490
1543
  const cut = f.asking === true;
1544
+ const handled = typeof f.handledAt === 'string' && f.handledAt.trim() !== '';
1491
1545
  if (cut) {
1492
- r.refund = { ...(f.amount ? { amount: f.amount } : {}), status: 'unsure' };
1546
+ r.refund = {
1547
+ ...(f.amount ? { amount: f.amount } : {}),
1548
+ status: 'unsure',
1549
+ ...(handled ? { handledAt: f.handledAt } : {}),
1550
+ };
1493
1551
  save();
1494
1552
  }
1553
+ if (handled)
1554
+ continue;
1555
+ const at = Date.parse(r.cancelledAt ?? r.createdAt);
1556
+ if (!cut && Number.isFinite(at) && at < saidSince) {
1557
+ older.push(r.id);
1558
+ continue;
1559
+ }
1495
1560
  log(`[otaless] NEEDS A PERSON: ${forTheLog(r.id)} at ${r.group} is cancelled, and its refund (9.1) ${cut ? 'was being asked when the service stopped - whether it was sent is not known' : f.status === 'unsure' ? 'was not answered - whether it was sent is not known' : 'was not sent'}`);
1496
1561
  }
1562
+ if (older.length)
1563
+ log(`[otaless] ${older.length} cancelled more than ${REFUND_SAID_DAYS} days ago still ${older.length === 1 ? 'has its refund' : 'have their refunds'} not sent or not known (${older
1564
+ .slice(0, 10)
1565
+ .map((id) => forTheLog(id))
1566
+ .join(', ')}${older.length > 10 ? ', …' : ''}) - each was logged when it happened, as one for a person; once a person has taken one up, write refund.handledAt on it in otaless-orders.json (service stopped)`);
1497
1567
  /**
1498
1568
  * ⚠️ AN ORDER 8 NAMES THAT IS ONE OF OURS ALREADY IS NOT TOUCHED (总线程's
1499
1569
  * review of 0.68.2, P2): a refusal - "already booked", say - may name the
@@ -1674,6 +1744,11 @@ export const createOtalessBookings = (deps) => {
1674
1744
  const code = text(w.originalOrderId) ?? '';
1675
1745
  if (knownNamed(a, id, code))
1676
1746
  return untouched(a, id, 'answered');
1747
+ // ⚠️ AN ORDER MADE AT THE GROUP SAYS THE BACKEND HOLDS ITS SESSION FOR THIS ACCOUNT (0.74.5,
1748
+ // 总线程 11-17: robin's AT-F2519E, booked on a link from before links were remembered, under
1749
+ // an account page saying "Link membership"): the account remembers the group as linked -
1750
+ // whatever is checked of the order below.
1751
+ deps.auth?.booked?.(a.acct.key, a.group);
1677
1752
  const page = text(w.checkoutUrl ?? undefined);
1678
1753
  // ⚠️ "CONFIRMED" WITH A PAYMENT PAGE IS WAITING FOR ITS PAYMENT (questions
1679
1754
  // #53, #61 (1) - 8's own example): paid is what 15 says, never this status.
@@ -1967,6 +2042,9 @@ export const createOtalessBookings = (deps) => {
1967
2042
  // 8's step 1 (0.72.1): the group's terms asked for. Not sent at a group that asks
1968
2043
  // for no terms - nor after the guest agreed to them: steps 2 and 3 carry the token.
1969
2044
  ...(a.groupTerms === 'ask' ? { termsRequired: true } : {}),
2045
+ // ⚠️ ACCOR: ITS COUNTRY, A LANGUAGE AND A CURRENCY, AS ITS ROOMS AND QUOTE (0.74.5 -
2046
+ // its /rooms refuses without them; 8 not tried on the real backend: it orders).
2047
+ ...localeAsked(a.hotel.supplier ?? a.group, a.hotel.countryCode),
1970
2048
  };
1971
2049
  const cred8 = { token: cred.token, ...(session ? { session } : {}) };
1972
2050
  const send = async (b) => {
@@ -2362,9 +2440,12 @@ export const createOtalessBookings = (deps) => {
2362
2440
  !Array.isArray(e.groups))
2363
2441
  throw err;
2364
2442
  stayRefusals.push(err);
2443
+ // ⚠️ WITH ITS CODE (0.74.5): the card says it in its own words, with the way to link or
2444
+ // sign in - the message is the model's ("…the guest presses Book again").
2445
+ const code = e.code === 'sign-in' ? (e.groups.length ? 'link-first' : 'sign-in') : 'signed-out';
2365
2446
  return {
2366
2447
  failed: {
2367
- ...failedStay(label, err.message),
2448
+ ...failedStay(label, err.message, code),
2368
2449
  ...(e.groups.length ? { groups: [...e.groups] } : {}),
2369
2450
  },
2370
2451
  };
@@ -2956,6 +3037,9 @@ export const createOtalessBookings = (deps) => {
2956
3037
  cancellable: true,
2957
3038
  feeIsCap: true,
2958
3039
  feeUnknown: true,
3040
+ // ⚠️ `rule` IS OURS, FOR THE MODEL (0.74.5): the card says this in its own words, never
3041
+ // under "the group's own words".
3042
+ termsNew: true,
2959
3043
  };
2960
3044
  // ⚠️ THE GROUP'S OWN TERMS, AS THEY CAME; ONLY WITHOUT THEM THE CAP
2961
3045
  // (总线程 11-10). There is no dry run: what is kept is the group's to say