@curless/hotel-storefront 0.84.0 → 0.84.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (99) hide show
  1. package/dist/account/addon-pages.d.ts.map +1 -1
  2. package/dist/account/addon-pages.js +23 -7
  3. package/dist/account/addon-pages.js.map +1 -1
  4. package/dist/account/cancel-pages.d.ts +118 -0
  5. package/dist/account/cancel-pages.d.ts.map +1 -0
  6. package/dist/account/cancel-pages.js +313 -0
  7. package/dist/account/cancel-pages.js.map +1 -0
  8. package/dist/account/index.d.ts +50 -1
  9. package/dist/account/index.d.ts.map +1 -1
  10. package/dist/account/index.js +389 -34
  11. package/dist/account/index.js.map +1 -1
  12. package/dist/account/pages.d.ts +31 -3
  13. package/dist/account/pages.d.ts.map +1 -1
  14. package/dist/account/pages.js +98 -19
  15. package/dist/account/pages.js.map +1 -1
  16. package/dist/account/requests.d.ts +11 -1
  17. package/dist/account/requests.d.ts.map +1 -1
  18. package/dist/account/requests.js +2 -1
  19. package/dist/account/requests.js.map +1 -1
  20. package/dist/card.generated.d.ts +1 -1
  21. package/dist/card.generated.js +2 -2
  22. package/dist/card.generated.js.map +1 -1
  23. package/dist/config.d.ts +14 -5
  24. package/dist/config.d.ts.map +1 -1
  25. package/dist/config.js +2 -0
  26. package/dist/config.js.map +1 -1
  27. package/dist/legal.d.ts.map +1 -1
  28. package/dist/legal.js +4 -3
  29. package/dist/legal.js.map +1 -1
  30. package/dist/otaless/addons-answers.d.ts +2 -0
  31. package/dist/otaless/addons-answers.d.ts.map +1 -1
  32. package/dist/otaless/addons-answers.js +32 -12
  33. package/dist/otaless/addons-answers.js.map +1 -1
  34. package/dist/otaless/addons.d.ts +16 -4
  35. package/dist/otaless/addons.d.ts.map +1 -1
  36. package/dist/otaless/addons.js +25 -12
  37. package/dist/otaless/addons.js.map +1 -1
  38. package/dist/otaless/backend.d.ts.map +1 -1
  39. package/dist/otaless/backend.js +55 -1
  40. package/dist/otaless/backend.js.map +1 -1
  41. package/dist/otaless/booking.d.ts +39 -4
  42. package/dist/otaless/booking.d.ts.map +1 -1
  43. package/dist/otaless/booking.js +406 -61
  44. package/dist/otaless/booking.js.map +1 -1
  45. package/dist/otaless/client.d.ts.map +1 -1
  46. package/dist/otaless/client.js +3 -1
  47. package/dist/otaless/client.js.map +1 -1
  48. package/dist/otaless/fake.d.ts +14 -0
  49. package/dist/otaless/fake.d.ts.map +1 -1
  50. package/dist/otaless/fake.js +18 -8
  51. package/dist/otaless/fake.js.map +1 -1
  52. package/dist/otaless/make.d.ts.map +1 -1
  53. package/dist/otaless/make.js +19 -3
  54. package/dist/otaless/make.js.map +1 -1
  55. package/dist/otaless/shop-answers.d.ts +100 -3
  56. package/dist/otaless/shop-answers.d.ts.map +1 -1
  57. package/dist/otaless/shop-answers.js +271 -26
  58. package/dist/otaless/shop-answers.js.map +1 -1
  59. package/dist/otaless/shop-client.d.ts +7 -0
  60. package/dist/otaless/shop-client.d.ts.map +1 -1
  61. package/dist/otaless/shop-client.js +5 -0
  62. package/dist/otaless/shop-client.js.map +1 -1
  63. package/dist/otaless/shop-fake.d.ts +5 -0
  64. package/dist/otaless/shop-fake.d.ts.map +1 -1
  65. package/dist/otaless/shop-fake.js +2 -0
  66. package/dist/otaless/shop-fake.js.map +1 -1
  67. package/dist/otaless/shop-record.d.ts +24 -0
  68. package/dist/otaless/shop-record.d.ts.map +1 -0
  69. package/dist/otaless/shop-record.js +128 -0
  70. package/dist/otaless/shop-record.js.map +1 -0
  71. package/dist/otaless/shop-service.d.ts +60 -3
  72. package/dist/otaless/shop-service.d.ts.map +1 -1
  73. package/dist/otaless/shop-service.js +169 -8
  74. package/dist/otaless/shop-service.js.map +1 -1
  75. package/dist/otaless/shop.d.ts +44 -0
  76. package/dist/otaless/shop.d.ts.map +1 -1
  77. package/dist/otaless/shop.js +97 -0
  78. package/dist/otaless/shop.js.map +1 -1
  79. package/dist/otaless/wallet.d.ts.map +1 -1
  80. package/dist/otaless/wallet.js +27 -6
  81. package/dist/otaless/wallet.js.map +1 -1
  82. package/dist/server.d.ts +1 -1
  83. package/dist/server.d.ts.map +1 -1
  84. package/dist/server.js +153 -8
  85. package/dist/server.js.map +1 -1
  86. package/dist/surface.d.ts.map +1 -1
  87. package/dist/surface.js +5 -1
  88. package/dist/surface.js.map +1 -1
  89. package/dist/tools.d.ts +79 -19
  90. package/dist/tools.d.ts.map +1 -1
  91. package/dist/tools.js +452 -42
  92. package/dist/tools.js.map +1 -1
  93. package/dist/trip-ids.d.ts +39 -2
  94. package/dist/trip-ids.d.ts.map +1 -1
  95. package/dist/trip-ids.js +80 -3
  96. package/dist/trip-ids.js.map +1 -1
  97. package/dist/types.d.ts +20 -0
  98. package/dist/types.d.ts.map +1 -1
  99. package/package.json +1 -1
@@ -5,6 +5,7 @@ import { formatMoney, inFullCurrency } from '../money.js';
5
5
  import { ADDON_TICKET_MS } from '../otaless/addons.js';
6
6
  import { withTrip } from '../trip-ids.js';
7
7
  import { addonDonePage, addonPage, addonStatePage } from './addon-pages.js';
8
+ import { CANCEL_TICKET_MS, cancelDonePage, cancelPage, cancelStatePage, } from './cancel-pages.js';
8
9
  import { AccountInfos } from './info-cache.js';
9
10
  import { maskEmail } from './mask.js';
10
11
  import { ADDON_PATHS, LIMITS, OTA_PATHS, OtaMemberError, linkOf, makeOtaMembers, maskLabel, maskNumber, } from './ota-member.js';
@@ -388,6 +389,8 @@ export const makeAccount = (opts) => {
388
389
  const lax = sameSite === 'Lax';
389
390
  /** " The page is for the guest alone…" - beside a link to our pages in words, under Lax only. */
390
391
  const aloneSaid = (noCards) => lax && noCards === true ? ` ${GUEST_ALONE}` : '';
392
+ /** The account page opened in a browser not signed in (0.84.2, the UI review's P2-6). */
393
+ const notSignedInThere = () => `If that page says to open the account from the chat, the browser they opened it in is not signed in (another browser, or more than ${WEB_IDLE_MS / 60_000} minutes since): with their yes, sign them out (${names.signOut}) and in again (${names.signIn}) - its one-time page signs that browser in - then give them the account page again.`;
391
394
  /** The account's no, naming what it signs in with: the email. */
392
395
  const signInFailed = 'sign_in_failed_email';
393
396
  /** Not an email: said on the page, nothing sent, nothing counted. */
@@ -524,6 +527,14 @@ export const makeAccount = (opts) => {
524
527
  // …and one for an add-on's confirm (0.82.0): used once, ten minutes at most.
525
528
  const addonRequests = createSignIns({ now, ttlMs: ADDON_TICKET_MS, perKey: 10 });
526
529
  const addonCsrf = (r) => createHmac('sha256', secretKey).update(`addon:${r.codeHash}`).digest('base64url').slice(0, 32);
530
+ // …and one for a booking's cancel (0.84.2, P1-8): used once, ten minutes at most.
531
+ const cancelRequests = createSignIns({ now, ttlMs: CANCEL_TICKET_MS, perKey: 10 });
532
+ const cancelCsrf = (r) => createHmac('sha256', secretKey).update(`cancel:${r.codeHash}`).digest('base64url').slice(0, 32);
533
+ /** What each cancel link shows - the tool's preview, as facts - in memory only, as long as its request is kept. */
534
+ const cancelFacts = new WeakMap();
535
+ /** What its press came to, shown again on the used link to the same account's browser. */
536
+ const cancelDone = new WeakMap();
537
+ const cancelOn = opts.account.cancelOnPage === true && !!opts.cancels;
527
538
  const remembered = new Map();
528
539
  const clip = (v, n) => typeof v === 'string' && v.trim() ? v.trim().slice(0, n) : undefined;
529
540
  /**
@@ -908,7 +919,15 @@ export const makeAccount = (opts) => {
908
919
  .catch((e) => log(`[account] the backend's sign-out did not answer (${codeOf(e)})`));
909
920
  };
910
921
  /** A session of the account's own - with no memberships of ours on it - ended at the backend (not waited for). */
911
- const endSession = (p) => signOutAll(p.access, p);
922
+ /**
923
+ * ⚠️ A SIGN-IN REFUSED HERE IS LET GO, NOT ENDED AT THE BACKEND (0.84.2, the 11-25 code audit's
924
+ * P2-26): another account than the link's, a link no longer this conversation's, every place taken -
925
+ * a sign-out there (no providerCode) ended every channel of THAT member: a guest who signed in on a link
926
+ * someone else sent them was rightly refused, and logged out of all their own conversations and
927
+ * group links with it. As 0.82.2 did for the idle sign-out: the token is dropped here, never kept,
928
+ * never sent anywhere; the backend lets it lapse.
929
+ */
930
+ const letGoOf = (_p) => { };
912
931
  /**
913
932
  * A sign-in that is over: its pages closed, its memberships forgotten, every channel
914
933
  * of its token ended at the backend (not waited for, `signOutAll`).
@@ -923,7 +942,7 @@ export const makeAccount = (opts) => {
923
942
  web.dropFor(s.sid);
924
943
  infos.forget(s.shown.id);
925
944
  s.links?.clear();
926
- log(`[account] a sign-in ${why === 'lapsed' ? 'lapsed' : why === 'replaced' ? 'was replaced' : 'was signed out by the guest'} here - forgotten here only, not signed out at the backend (its memberships stay linked there)`);
945
+ log(`[account] a sign-in ${why === 'lapsed' ? 'lapsed' : why === 'replaced' ? 'was replaced' : why === 'taken-over' ? 'ended with a take-over' : 'was signed out by the guest'} here - forgotten here only, not signed out at the backend (its memberships stay linked there)`);
927
946
  };
928
947
  const end = (s) => {
929
948
  web.dropFor(s.sid);
@@ -935,11 +954,21 @@ export const makeAccount = (opts) => {
935
954
  s.links?.clear();
936
955
  void signOutAll(s.platform.access, s.platform, each);
937
956
  };
957
+ /** The guest's own sign-out, told to the server (0.84.1, `onSignedOut`) - never a forget or a take-over. */
958
+ const signedOut = (key) => {
959
+ try {
960
+ opts.onSignedOut?.(key);
961
+ }
962
+ catch {
963
+ log(`[account] ${tag(key)}: a sign-out was not told on`);
964
+ }
965
+ };
938
966
  const signOut = (key) => {
939
967
  const was = store.clear(key);
940
968
  requests.cancelFor(key);
941
969
  linkRequests.cancelFor(key);
942
970
  termsRequests.cancelFor(key);
971
+ cancelRequests.cancelFor(key);
943
972
  // The guest's own sign-out: here only where the deployment keeps links (0.82.2), else at the
944
973
  // backend too - every channel of the token.
945
974
  if (was) {
@@ -1133,8 +1162,13 @@ export const makeAccount = (opts) => {
1133
1162
  const walletPart = opts.wallet
1134
1163
  ? makeWalletPart({ wallet: opts.wallet, meta: walletMeta, now, log })
1135
1164
  : undefined;
1136
- /** The account page's wallet block - the page the guest does everything on. */
1137
- const walletUrl = (lang) => `${publicUrl}/account?lang=${lang}#wallet`;
1165
+ /**
1166
+ * The account page's wallet block - the page the guest does everything on. ⚠️ IN THE BROWSER'S OWN
1167
+ * LANGUAGE (0.84.2, the 11-25 UI review's P2-5 - walkthrough #20): `?lang=` was the deployment's
1168
+ * (`en`), so a Chinese chat's guest got the wallet in English. Left out, the page reads the
1169
+ * browser's, as the terms page does. (`lang` is kept in the signature for the callers.)
1170
+ */
1171
+ const walletUrl = (_lang) => `${publicUrl}/account#wallet`;
1138
1172
  const walletCtx = (s, key, ip) => ({
1139
1173
  // The same rows the page and the card show: linked, and not one that needs linking again.
1140
1174
  linkedOf: (group) => {
@@ -1159,8 +1193,12 @@ export const makeAccount = (opts) => {
1159
1193
  ...(linking ? { linkTool: names.link } : {}),
1160
1194
  said: (c) => walletSaid(c, noCards),
1161
1195
  }) ?? '';
1162
- // The account page's link, in words (0.84.0, Lax): the guest's alone to press.
1163
- return said.includes(walletUrl(lang)) ? `${said}${aloneSaid(noCards)}` : said;
1196
+ // The account page's link, in words (0.84.0, Lax): the guest's alone to press. ⚠️ AND WHAT TO DO
1197
+ // WHEN IT SAYS "OPEN YOUR ACCOUNT FROM YOUR CHAT" (0.84.2, the UI review's P2-6): the browser is
1198
+ // not signed in (another one, or past 30 minutes) - the sign-in link first.
1199
+ return said.includes(walletUrl(lang))
1200
+ ? `${said}${aloneSaid(noCards)}${noCards ? ` ${notSignedInThere()}` : ''}`
1201
+ : said;
1164
1202
  };
1165
1203
  /** An answer with the wallets read now: the same facts in the structure (the card's, the model's) and in the words. */
1166
1204
  const withWallets = async (s, key, answer, lang, noCards, ip) => {
@@ -1552,10 +1590,11 @@ export const makeAccount = (opts) => {
1552
1590
  const ends = Date.parse(c.until);
1553
1591
  if (!Number.isFinite(ends) || ends <= now())
1554
1592
  return undefined;
1555
- const l = langOf(lang);
1593
+ // ⚠️ IN THE BROWSER'S OWN LANGUAGE (0.84.2, the 11-25 UI review's P2-5 - walkthrough #20): the
1594
+ // deployment's (`en`) went with the link, and a Chinese chat's guest confirmed - the page that
1595
+ // moves money - in English, right after a terms page in Chinese. As the terms link: no `lang`.
1556
1596
  const made = addonRequests.create({
1557
1597
  key,
1558
- ...(l ? { lang: l } : {}),
1559
1598
  words: true,
1560
1599
  addon: { ref, sid: s.sid },
1561
1600
  });
@@ -1565,10 +1604,38 @@ export const makeAccount = (opts) => {
1565
1604
  made.request.expires = Math.min(made.request.expires, ends);
1566
1605
  log(`[account] an add-on confirm link for ${tag(key)}`);
1567
1606
  return {
1568
- url: `${publicUrl}/account?addon=${made.code}${l ? `&lang=${l}` : ''}`,
1607
+ url: `${publicUrl}/account?addon=${made.code}`,
1569
1608
  expiresAt: new Date(made.request.expires).toISOString(),
1570
1609
  };
1571
1610
  };
1611
+ /**
1612
+ * The one-time cancel page's link (0.84.2, the 11-25 code audit's P1-8 - `account.cancelOnPage`): bound
1613
+ * to the conversation and its sign-in, counted against the conversation like a membership link, ten
1614
+ * minutes at most. No `lang`: the page takes the browser's own, as the terms and add-on links.
1615
+ */
1616
+ const cancelLink = (key, facts) => {
1617
+ if (!cancelOn)
1618
+ return undefined;
1619
+ const s = store.get(key);
1620
+ if (!s)
1621
+ return undefined;
1622
+ if (counters.links.count(`link:${key}`) >= ACCOUNT_LIMITS.linksPerConversation) {
1623
+ refusals.links++;
1624
+ return undefined;
1625
+ }
1626
+ const made = cancelRequests.create({
1627
+ key,
1628
+ words: true,
1629
+ cancel: { ref: facts.booking.id, sid: s.sid },
1630
+ });
1631
+ if (!made)
1632
+ return undefined;
1633
+ counters.links.add(`link:${key}`);
1634
+ const until = new Date(made.request.expires).toISOString();
1635
+ cancelFacts.set(made.request, { ...facts, until });
1636
+ log(`[account] a cancel link for ${tag(key)}`);
1637
+ return { url: `${publicUrl}/account?cancel=${made.code}`, expiresAt: until };
1638
+ };
1572
1639
  /**
1573
1640
  * A guest's press on a one-time page (0.84.0, `account.pressCountsAsUse` only): the conversation in use
1574
1641
  * now - see `AccountOptions.onPressed`. Never in a request's way.
@@ -1648,6 +1715,8 @@ export const makeAccount = (opts) => {
1648
1715
  }
1649
1716
  if (name === names.signOut) {
1650
1717
  const was = signOut(key);
1718
+ if (was)
1719
+ signedOut(key);
1651
1720
  if (!was)
1652
1721
  return {
1653
1722
  text: !noCards && !call.fromCard
@@ -1752,6 +1821,12 @@ export const makeAccount = (opts) => {
1752
1821
  ];
1753
1822
  /** The wallet groups as the descriptions and the words name them. */
1754
1823
  const walletNamesSaid = (walletPart?.groups ?? []).map((g) => walletMeta(g).name).join(', ');
1824
+ // ⚠️ ONE WALLET PER GROUP, NEVER ONE FOR ALL (0.84.2, the 11-25 code audit's P2-19): "the guest's JI
1825
+ // Hotel, Atour, Ascott, Shangri-La, Club Med wallet" read as one shared credit line.
1826
+ const walletGroups = (walletPart?.groups ?? []).map((g) => walletMeta(g).name);
1827
+ const walletsSaid = walletGroups.length > 1
1828
+ ? `wallets at ${walletGroups.slice(0, -1).join(', ')} and ${walletGroups.at(-1)} - one per hotel group, each its own credit line`
1829
+ : `${walletNamesSaid} wallet`;
1755
1830
  /** The card tool's wallet properties - only with the switch on (the frozen listing). */
1756
1831
  const walletProps = () => ({
1757
1832
  walletGroup: { type: 'string', enum: [...(walletPart?.groups ?? [])] },
@@ -1796,7 +1871,7 @@ export const makeAccount = (opts) => {
1796
1871
  // That rule is the SERVER INSTRUCTIONS' (`instructions` below, both versions), not this
1797
1872
  // description's (0.75.0, T1: OpenAI - a description says what a tool does, not how the
1798
1873
  // model should use it).
1799
- description: `Whether the guest is signed in to their ${brand} account in this conversation, and the name the account goes by (its nickname where it has one). Its contact details are not given: they are on ${brand}'s account page.${walletPart ? ` It also reads the guest's ${walletNamesSaid} wallet, read only: available, authorized, charged and held credit in US dollars, the cards on it (brand, last four digits, expiry), its limits and the latest transactions.` : ''}`,
1874
+ description: `Whether the guest is signed in to their ${brand} account in this conversation, and the name the account goes by (its nickname where it has one). Its contact details are not given: they are on ${brand}'s account page.${walletPart ? ` It also reads the guest's ${walletsSaid}, read only: available, authorized, charged and held credit in US dollars, the cards on each (brand, last four digits, expiry), its limits and the latest transactions.` : ''}`,
1800
1875
  annotations: {
1801
1876
  title: `My ${brand} account`,
1802
1877
  readOnlyHint: true,
@@ -1865,7 +1940,7 @@ export const makeAccount = (opts) => {
1865
1940
  {
1866
1941
  name: names.card,
1867
1942
  // The card's own (app-only, server.ts): never offered to the assistant.
1868
- description: `The booking card's own way to sign in to the ${brand} account, see who is signed in, or sign out - for the conversation the card was drawn for. The same steps as ${names.signIn}, ${linking ? `${names.view}, ${names.signOut} and ${names.link}` : `${names.view} and ${names.signOut}`}, called by the card itself.${walletPart ? ` And the ${walletNamesSaid} wallet's steps, each pressed by the guest on the card: add a card, authorize an amount, change limits, renew, remove a card.` : ''}`,
1943
+ description: `The booking card's own way to sign in to the ${brand} account, see who is signed in, or sign out - for the conversation the card was drawn for. The same steps as ${names.signIn}, ${linking ? `${names.view}, ${names.signOut} and ${names.link}` : `${names.view} and ${names.signOut}`}, called by the card itself.${walletPart ? ` And the steps of the ${walletsSaid}, each pressed by the guest on the card: add a card, authorize an amount, change limits, renew, remove a card.` : ''}`,
1869
1944
  annotations: {
1870
1945
  title: `${brand} account (card)`,
1871
1946
  readOnlyHint: false,
@@ -1996,7 +2071,7 @@ export const makeAccount = (opts) => {
1996
2071
  ? ` HOTEL MEMBERSHIPS: a guest signed in to ${brand} can link a hotel group's loyalty membership to the account - ${memberships.map(groupName).join(', ')} - and that group's prices here are then asked for as the member. ${names.link} gives a one-time page for it (or joins the group, or unlinks); the group's email and password are typed on that page, never in the chat - never ask for or accept them here, and never write one back. Say a price is a member rate only where the answer says so.`
1997
2072
  : '';
1998
2073
  const WALLET_SAID = (noCards) => walletPart
1999
- ? ` ${walletNamesSaid.toUpperCase()} WALLET: the account view (${names.view}) also shows the guest's ${walletNamesSaid} wallet - a credit line in US dollars that the guest authorizes on their own bank card, not a deposit. Read it for them when they ask and say what it shows. Adding a card, authorizing an amount, changing limits, renewing and removing a card are done by the guest ${noCards ? 'on the account page whose link the answer gives' : 'on the card or on the account page'}, never by you for them: do not offer to do them, and never say that money was added - an authorization is not a deposit.`
2074
+ ? ` ${walletGroups.length > 1 ? 'WALLETS' : `${walletNamesSaid.toUpperCase()} WALLET`}: the account view (${names.view}) also shows the guest's ${walletsSaid} - ${walletGroups.length > 1 ? 'each ' : ''}a credit line in US dollars that the guest authorizes on their own bank card, not a deposit. Read it for them when they ask and say what it shows. Adding a card, authorizing an amount, changing limits, renewing and removing a card are done by the guest ${noCards ? 'on the account page whose link the answer gives' : 'on the card or on the account page'}, never by you for them: do not offer to do them, and never say that money was added - an authorization is not a deposit.`
2000
2075
  : '';
2001
2076
  const instructions = (noCards) => (noCards
2002
2077
  ? `${brand} ACCOUNT: a guest who wants to sign in to their ${brand} account, or create one, is given a one-time page by ${names.signIn}: pass on its link and its code exactly, and say they sign in or create the account on that page. Never ask for, or accept, a password in the chat, nor the email or phone number to sign in or link a membership with; if the guest types one of them, never write it back, whole or in part - not even to say which one to change or not to use again: call it \"the password you typed\" - and tell them to use the page and, as it went into a chat, to choose another, without naming the old one. The name, email and phone number a booking asks for are the booking's own details, not the account's: ask for them in the chat, as that booking tool needs them. When they say they are done, ${names.view} - with the conversation's trip, as every call - shows who is signed in; use it only when they ask, never on your own and never beside a list of hotels or a search; ${names.signOut} signs them out.${linking ? '' : ' Being signed in changes no price here: say nothing of member rates.'}`
@@ -2097,7 +2172,7 @@ export const makeAccount = (opts) => {
2097
2172
  return at.ws &&
2098
2173
  at.s &&
2099
2174
  at.ws.key === r.key &&
2100
- at.s.sid === (r.link ?? r.terms ?? r.addon)?.sid
2175
+ at.s.sid === (r.link ?? r.terms ?? r.addon ?? r.cancel)?.sid
2101
2176
  ? { id: at.id, s: at.s }
2102
2177
  : null;
2103
2178
  };
@@ -2215,12 +2290,12 @@ export const makeAccount = (opts) => {
2215
2290
  const who = shownOf(proved.session, proved.profile, account);
2216
2291
  if (!still || still.sid !== r.link?.sid) {
2217
2292
  if (!still || !same(proved.session, still.platform))
2218
- void endSession(proved.session);
2293
+ letGoOf(proved.session);
2219
2294
  return notOpen(c, code, 'expired', lang, false);
2220
2295
  }
2221
2296
  if (who.id !== still.shown.id) {
2222
2297
  if (!same(proved.session, still.platform))
2223
- void endSession(proved.session);
2298
+ letGoOf(proved.session);
2224
2299
  log(`[account] a membership link of ${tag(r.key)} opened by another account: refused`);
2225
2300
  return reauthPage(c, code, r, lang, 'reauth_other');
2226
2301
  }
@@ -2456,6 +2531,11 @@ export const makeAccount = (opts) => {
2456
2531
  rooms: t.rooms,
2457
2532
  guests: t.stay.guests,
2458
2533
  total: inFullCurrency(opts.fullCurrency, () => formatMoney(t.total)),
2534
+ ...(t.payAs
2535
+ ? {
2536
+ payAs: inFullCurrency(opts.fullCurrency, () => formatMoney(t.payAs)),
2537
+ }
2538
+ : {}),
2459
2539
  });
2460
2540
  const termsView = (c, code, r, t, lang) => {
2461
2541
  const logo = logoPath(t.group);
@@ -2572,6 +2652,20 @@ export const makeAccount = (opts) => {
2572
2652
  false,
2573
2653
  'failed',
2574
2654
  ],
2655
+ // 0.84.2 (the 11-25 code audit's P2-4): both made an order and cancelled it at once - never
2656
+ // "could not order".
2657
+ 'currency-mismatch': [
2658
+ '{g}下单用的币种和报价不一样,已经立即取消,没有扣款。这个价现在这里订不了,可以换房型、日期或酒店,或去{g}官网 / App 订。',
2659
+ '{g} took the order in another currency than the price you were shown, so it was cancelled at once and nothing was charged. This price cannot be booked here just now: choose another room, other dates or another hotel, or book on {g}’s own website or app.',
2660
+ false,
2661
+ 'failed',
2662
+ ],
2663
+ 'pay-page-refused': [
2664
+ '{g}发来的付款页地址对不上这一单,已经立即取消,没有扣款。',
2665
+ 'The payment page {g} sent does not match this order, so it was cancelled at once and nothing was charged.',
2666
+ false,
2667
+ 'failed',
2668
+ ],
2575
2669
  'needs-person': [
2576
2670
  '{g}生成了一张和你看到的不一样的单,我们没能取消,已转人工,请不要付款。这张单在对话里的「我的预订」中。',
2577
2671
  '{g} made an order that is not the one you were shown, and we could not cancel it. A person is looking at it - please do not pay it. It is in My bookings in your chat.',
@@ -2706,12 +2800,12 @@ export const makeAccount = (opts) => {
2706
2800
  const who = shownOf(proved.session, proved.profile, account);
2707
2801
  if (!still || still.sid !== r.terms.sid) {
2708
2802
  if (!still || !sameTok(proved.session, still.platform))
2709
- void endSession(proved.session);
2803
+ letGoOf(proved.session);
2710
2804
  return termsNotOpen(c, code, 'expired', lang, false);
2711
2805
  }
2712
2806
  if (who.id !== still.shown.id) {
2713
2807
  if (!sameTok(proved.session, still.platform))
2714
- void endSession(proved.session);
2808
+ letGoOf(proved.session);
2715
2809
  log(`[account] a terms link of ${tag(r.key)} opened by another account: refused`);
2716
2810
  return termsReauth(c, code, r, lang, 'reauth_other');
2717
2811
  }
@@ -2792,14 +2886,28 @@ export const makeAccount = (opts) => {
2792
2886
  return send(c, 200, termsResult(r, code, lang, termsErrorDone('terms-gone', lang, groupName, logo)));
2793
2887
  }
2794
2888
  const booking = asObj(st.booking);
2889
+ // ⚠️ 8 NOT ANSWERED, OR ANSWERED WITH A SERVER ERROR (0.84.2, the 11-25 code audit's P1-2): the
2890
+ // booking is `unconfirmed` - whether it was made is not known. Never "Confirmed by {group}",
2891
+ // never its `pending:…` id as an order number: "not known yet, do not order again".
2892
+ if (view === 'booking' &&
2893
+ asStr(booking.hotelName) &&
2894
+ asStr(booking.status) === 'unconfirmed') {
2895
+ log(`[account] terms agreed k=${tag(r.key)} group=${groupCode} → unconfirmed`);
2896
+ return send(c, 200, termsResult(r, code, lang, termsErrorDone('unconfirmed', lang, groupName, logo)));
2897
+ }
2795
2898
  if (view === 'booking' && asStr(booking.hotelName)) {
2796
2899
  const pay = asObj(booking.payment);
2797
2900
  const status = asStr(pay.status);
2901
+ // ⚠️ SAID AS WHAT IS KNOWN (0.84.2, P1-2 / P0-1): paid - by its page, or when it was booked;
2902
+ // waiting for its payment; confirmed with no page, whether it was charged not known
2903
+ // (`unknown`); else confirmed by the group.
2798
2904
  const paid = status === 'paid'
2799
2905
  ? 'paid'
2800
2906
  : status === 'awaiting' || (!status && asStr(pay.url))
2801
2907
  ? 'awaiting'
2802
- : 'confirmed';
2908
+ : booking.paymentUnknown === true
2909
+ ? 'unknown'
2910
+ : 'confirmed';
2803
2911
  const stay = asObj(booking.stay);
2804
2912
  const facts = before
2805
2913
  ? termsFactsOf(before, lang)
@@ -2815,6 +2923,7 @@ export const makeAccount = (opts) => {
2815
2923
  const payByWords = asStr(pay.payByWords);
2816
2924
  const payHost = asStr(pay.host);
2817
2925
  const payAmount = asStr(pay.amount);
2926
+ const quotedAs = asStr(pay.quotedAs);
2818
2927
  const confirmation = asStr(booking.confirmationCode);
2819
2928
  return send(c, 200, termsResult(r, code, lang, {
2820
2929
  kind: 'ordered',
@@ -2828,6 +2937,8 @@ export const makeAccount = (opts) => {
2828
2937
  ...(payByWords ? { payByWords } : {}),
2829
2938
  ...(payUrl ? { payUrl } : {}),
2830
2939
  ...(payAmount ? { payAmount } : {}),
2940
+ ...(quotedAs && payAmount ? { quotedAs } : {}),
2941
+ ...(pay.chargedWhenBooked === true ? { chargedWhenBooked: true } : {}),
2831
2942
  }));
2832
2943
  }
2833
2944
  // A refusal - or a booking that came back with nothing booked.
@@ -3068,25 +3179,27 @@ export const makeAccount = (opts) => {
3068
3179
  if (!s) {
3069
3180
  requests.reopen(r);
3070
3181
  refusals.full++;
3071
- void endSession(got.session);
3182
+ letGoOf(got.session);
3072
3183
  log('[account] a sign-in refused: every place is taken by a live one');
3073
3184
  failed('failed');
3074
3185
  return again('busy');
3075
3186
  }
3076
3187
  requests.done(r);
3077
- // The shop, with the same email and password (0.82.1) - before the page says signed in, so
3078
- // the shop is there when the guest goes back to the chat; never in the account's way.
3079
- await shopWithAccount(r.key, typed, password, lang, {
3080
- tried: up,
3081
- ...(values.nickname ? { name: values.nickname } : {}),
3082
- });
3083
- // A new trip id for the conversation (0.75.1, risk A) - never in the sign-in's way.
3188
+ // A new trip id for the conversation (0.75.1, risk A) - never in the sign-in's way. ⚠️ BEFORE
3189
+ // THE SHOP'S SIGN-IN (0.84.2, the 11-25 code audit's P2-22): that waits up to ~45 s, and the
3190
+ // id from before the sign-in still reached the conversation just signed in all that while.
3084
3191
  try {
3085
3192
  opts.onSignedIn?.(r.key, r.codeHash);
3086
3193
  }
3087
3194
  catch {
3088
3195
  log(`[account] ${tag(r.key)}: its trip id was not given out again`);
3089
3196
  }
3197
+ // The shop, with the same email and password (0.82.1) - before the page says signed in, so
3198
+ // the shop is there when the guest goes back to the chat; never in the account's way.
3199
+ await shopWithAccount(r.key, typed, password, lang, {
3200
+ tried: up,
3201
+ ...(values.nickname ? { name: values.nickname } : {}),
3202
+ });
3090
3203
  usage({
3091
3204
  key: r.key,
3092
3205
  kind: 'account',
@@ -3112,6 +3225,35 @@ export const makeAccount = (opts) => {
3112
3225
  * only `wallet_confirm` with that ticket sends anything. A note on the way back is a short
3113
3226
  * code - no amount, no card digits in the URL.
3114
3227
  */
3228
+ /**
3229
+ * ⚠️ A CONFIRM PRESSED TWICE - A DOUBLE CLICK, A RELOAD THAT POSTS AGAIN (0.84.2, the 11-25 code
3230
+ * audit's P1-5): the first press took the ticket and was at the backend; the second found it
3231
+ * gone and was told "this confirmation has expired - nothing was done", which is the answer the
3232
+ * browser showed - while the first was authorizing. A guest who believed it went through the
3233
+ * steps again: a new ticket, a new key, a second authorization on the card. Now the press is
3234
+ * kept by its ticket, this account's alone: a second press of it waits for the first and is
3235
+ * shown the first's outcome - nothing is sent again. Renewing (one step, no ticket) is kept
3236
+ * the same way, by its card, for `WALLET_RENEW_MS` (the audit's P2-16). In
3237
+ * memory only; past `WALLET_PRESS_MAX`, the oldest go.
3238
+ */
3239
+ const walletPressed = new Map();
3240
+ const WALLET_PRESS_MS = 10 * 60_000;
3241
+ const WALLET_PRESS_MAX = 500;
3242
+ /** Renewing the same card again within this long is the same press (a double click, a reload). */
3243
+ const WALLET_RENEW_MS = 30_000;
3244
+ const walletPress = (key, owner, send, ms = WALLET_PRESS_MS) => {
3245
+ const was = walletPressed.get(key);
3246
+ if (was && was.owner === owner && now() - was.at < ms)
3247
+ return { again: true, done: was.done.catch(() => 'unknown') };
3248
+ for (const [k, v] of walletPressed)
3249
+ if (now() - v.at >= WALLET_PRESS_MS || walletPressed.size >= WALLET_PRESS_MAX)
3250
+ walletPressed.delete(k);
3251
+ else
3252
+ break;
3253
+ const done = send();
3254
+ walletPressed.set(key, { owner, done, at: now() });
3255
+ return { again: false, done };
3256
+ };
3115
3257
  const walletPost = async (c, at, body, lang) => {
3116
3258
  const part = walletPart;
3117
3259
  if (!part)
@@ -3129,6 +3271,8 @@ export const makeAccount = (opts) => {
3129
3271
  if (!part.offers(group))
3130
3272
  return send(c, 400, statePage(brandPage, lang, 'checked', plainHref('/account')));
3131
3273
  const owner = hashOf(at.id ?? '');
3274
+ // A press is this browser's sign-in's alone (0.84.2, P1-5): another of the same account's is not shown it.
3275
+ const presser = `${owner}|${hashOf(at.ws.key)}`;
3132
3276
  const cardId = formStr(body.cardId, 64);
3133
3277
  const code = (r) => r.outcome === 'done'
3134
3278
  ? 'done'
@@ -3149,7 +3293,10 @@ export const makeAccount = (opts) => {
3149
3293
  if (act === 'wallet_renew') {
3150
3294
  if (!cardId)
3151
3295
  return back('refused');
3152
- return back(code(await part.renew(ctx, { group, cardId })));
3296
+ const pressed = walletPress(`renew|${group}|${cardId}`, presser, async () => code(await part.renew(ctx, { group, cardId })), WALLET_RENEW_MS);
3297
+ if (pressed.again)
3298
+ log(`[account] ${tag(at.ws.key)} wallet renew pressed again - the first one's outcome`);
3299
+ return back(await pressed.done);
3153
3300
  }
3154
3301
  // ── Step one: a fresh read, a confirm page, a ticket.
3155
3302
  if (act === 'wallet_review_authorize' ||
@@ -3223,9 +3370,22 @@ export const makeAccount = (opts) => {
3223
3370
  // ── Step two: the ticket is taken (used) before anything is sent.
3224
3371
  if (act === 'wallet_confirm') {
3225
3372
  const ticketCode = formStr(body.ticket, 64);
3373
+ // Pressed already, by this account: the first press's outcome, nothing sent again.
3374
+ const first = ticketCode ? walletPressed.get(`ticket|${ticketCode}`) : undefined;
3375
+ if (first && first.owner === presser) {
3376
+ log(`[account] ${tag(at.ws.key)} wallet confirm pressed again - the first one's outcome`);
3377
+ return back(await first.done.catch(() => 'unknown'));
3378
+ }
3226
3379
  const t = part.take(owner, ticketCode);
3227
3380
  if (!t)
3228
3381
  return back('expired');
3382
+ const pressed = walletPress(`ticket|${ticketCode}`, presser, () => sendTicket(t, ticketCode));
3383
+ return back(await pressed.done);
3384
+ }
3385
+ return send(c, 400, statePage(brandPage, lang, 'checked', plainHref('/account')));
3386
+ async function sendTicket(t, ticketCode) {
3387
+ if (!part)
3388
+ return 'refused';
3229
3389
  // The ticket's own group, whatever the form says.
3230
3390
  const press = ticketCode;
3231
3391
  const r = t.kind === 'authorize'
@@ -3246,9 +3406,8 @@ export const makeAccount = (opts) => {
3246
3406
  })
3247
3407
  : await part.removeCard(ctx, { group: t.group, cardId: t.cardId, press });
3248
3408
  log(`[account] ${tag(at.ws.key)} wallet ${r.action} on the account page: ${r.outcome}${r.reason ? ` (${r.reason})` : ''}`);
3249
- return back(code(r));
3409
+ return code(r);
3250
3410
  }
3251
- return send(c, 400, statePage(brandPage, lang, 'checked', plainHref('/account')));
3252
3411
  };
3253
3412
  // ── An add-on's confirm, on its own page (0.82.0) ──────────────────────────────────────────
3254
3413
  // ⚠️ ON THE EXISTING PATH `/account`, TOLD APART BY ?addon= (Caddy passes fixed paths only).
@@ -3384,12 +3543,12 @@ export const makeAccount = (opts) => {
3384
3543
  const who = shownOf(proved.session, proved.profile, account);
3385
3544
  if (!still || still.sid !== r.addon.sid) {
3386
3545
  if (!still || !sameTok(proved.session, still.platform))
3387
- void endSession(proved.session);
3546
+ letGoOf(proved.session);
3388
3547
  return addonNotOpen(c, code, 'expired', lang);
3389
3548
  }
3390
3549
  if (who.id !== still.shown.id) {
3391
3550
  if (!sameTok(proved.session, still.platform))
3392
- void endSession(proved.session);
3551
+ letGoOf(proved.session);
3393
3552
  log(`[account] an add-on link of ${tag(r.key)} opened by another account: refused`);
3394
3553
  return addonReauth(c, code, r, lang, 'reauth_other');
3395
3554
  }
@@ -3450,6 +3609,180 @@ export const makeAccount = (opts) => {
3450
3609
  log(`[account] add-on confirm k=${tag(r.key)} ${done.result.action} → ${done.result.outcome}${done.result.reason ? ` (${done.result.reason})` : ''}${done.result.needsPerson ? ' NEEDS A PERSON' : ''}`);
3451
3610
  return send(c, 200, addonDonePage(brandPage, lang, code, done));
3452
3611
  };
3612
+ // ── A booking's cancel, on its own page (0.84.2, the 11-25 code audit's P1-8 - cancelOnPage) ───────
3613
+ // ⚠️ ON THE EXISTING PATH `/account`, TOLD APART BY ?cancel= (Caddy passes fixed paths only). Guarded
3614
+ // as the add-on page is: only the browser holding THIS account's sign-in opens it (`ownerOf`), else
3615
+ // the same account signs in again here; a POST comes from our page (Origin) with the request's own
3616
+ // token; one POST at a time (`begin`); used once - the press takes the link before anything is sent,
3617
+ // whatever comes back. A GET only shows. The press is the only thing that sends: `opts.cancels`
3618
+ // cancels only what the page showed (`facts.shape`). NOTHING OF THE BOOKING OR THE GUEST IS LOGGED.
3619
+ const cancelState = (r) => {
3620
+ const st = cancelRequests.state(r, false);
3621
+ if (st !== 'open')
3622
+ return st;
3623
+ return store.get(r.key)?.sid === r.cancel?.sid ? 'open' : 'expired';
3624
+ };
3625
+ const cancelNotOpen = (c, code, state, lang, r) => {
3626
+ const done = state === 'used' && r ? cancelDone.get(r) : undefined;
3627
+ const facts = r ? cancelFacts.get(r) : undefined;
3628
+ // The first press's outcome, to the same account's browser alone (a second press, a reload).
3629
+ if (done && r && facts && ownerOf(c, r))
3630
+ return send(c, 200, cancelDonePage(brandPage, lang, code, done, facts.group, true));
3631
+ return send(c, state === 'pending' ? 202 : state === 'tries' ? 429 : statusOf(state), cancelStatePage(brandPage, lang, state === 'used'
3632
+ ? 'used'
3633
+ : state === 'pending'
3634
+ ? 'pending'
3635
+ : state === 'unknown'
3636
+ ? 'unknown'
3637
+ : 'expired', code));
3638
+ };
3639
+ const cancelHref = (code) => (l) => `${base}/account?cancel=${encodeURIComponent(code)}&lang=${l}`;
3640
+ const cancelReauth = (c, code, r, lang, error, said) => send(c, 200, linkReauthPage(brandPage, {
3641
+ lang,
3642
+ code,
3643
+ csrf: cancelCsrf(r),
3644
+ group: brand,
3645
+ cancel: true,
3646
+ ...(error ? { error: say(lang, error, brand) } : {}),
3647
+ ...(error && said ? { said } : {}),
3648
+ }));
3649
+ const cancelShown = (c, code, r, lang) => {
3650
+ const facts = cancelFacts.get(r);
3651
+ if (!facts)
3652
+ return cancelNotOpen(c, code, 'unknown', lang);
3653
+ const payer = store.get(r.key)?.shown.email;
3654
+ return send(c, 200, cancelPage(brandPage, {
3655
+ lang,
3656
+ code,
3657
+ csrf: cancelCsrf(r),
3658
+ facts,
3659
+ ...(payer ? { account: payer } : {}),
3660
+ }));
3661
+ };
3662
+ const cancelGet = (c, code) => {
3663
+ const r = cancelRequests.find(code);
3664
+ const lang = langFor(c, r);
3665
+ if (over(c, 'pages', ipOf(c), ACCOUNT_LIMITS.pagesPerIp))
3666
+ return send(c, 429, statePage(brandPage, lang, 'limited', plainHref('/account')));
3667
+ if (!r?.cancel || !cancelOn)
3668
+ return cancelNotOpen(c, code, 'unknown', lang);
3669
+ const state = cancelState(r);
3670
+ if (state !== 'open')
3671
+ return cancelNotOpen(c, code, state, lang, r);
3672
+ const owner = ownerOf(c, r);
3673
+ if (!owner)
3674
+ return cancelReauth(c, code, r, lang);
3675
+ if (owner.id)
3676
+ setCookie(c, owner.id);
3677
+ return cancelShown(c, code, r, lang);
3678
+ };
3679
+ const cancelPost = async (c, body, code, lang) => {
3680
+ const r = cancelRequests.find(code);
3681
+ if (!r?.cancel || !cancelOn || !opts.cancels)
3682
+ return cancelNotOpen(c, code, 'unknown', lang);
3683
+ const state = cancelState(r);
3684
+ if (state !== 'open')
3685
+ return cancelNotOpen(c, code, state, lang, r);
3686
+ if (!same(body.csrf, cancelCsrf(r))) {
3687
+ refusals.csrf++;
3688
+ return send(c, 403, statePage(brandPage, lang, 'checked', cancelHref(code)));
3689
+ }
3690
+ if (!cancelRequests.tried(r)) {
3691
+ log(`[account] a cancel link for ${tag(r.key)} refused after too many tries`);
3692
+ return send(c, 429, statePage(brandPage, lang, 'tries', cancelHref(code)));
3693
+ }
3694
+ const s = store.get(r.key);
3695
+ if (!s || s.sid !== r.cancel.sid)
3696
+ return cancelNotOpen(c, code, 'expired', lang);
3697
+ // The account's own sign-in, again: it proves the browser is that account's.
3698
+ if (body.form === 'reauth') {
3699
+ const account = formStr(body.account, LIMITS.account).trim();
3700
+ const password = formStr(body.password, LIMITS.password);
3701
+ if (!account || !password)
3702
+ return cancelReauth(c, code, r, lang, 'missing_in_email');
3703
+ if (notAnEmail(account))
3704
+ return cancelReauth(c, code, r, lang, 'email_only');
3705
+ const named = `a:${account.toLowerCase()}`;
3706
+ if (nameFailures.shut(named, ACCOUNT_LIMITS.perName)) {
3707
+ refusals.names++;
3708
+ return cancelReauth(c, code, r, lang, 'too_many');
3709
+ }
3710
+ if (over(c, 'all', 'in', ACCOUNT_LIMITS.signInsPerMinute))
3711
+ return send(c, 429, statePage(brandPage, lang, 'limited', cancelHref(code)));
3712
+ if (!cancelRequests.begin(r))
3713
+ return cancelNotOpen(c, code, 'pending', lang);
3714
+ if (!nameFailures.enter(named, ACCOUNT_LIMITS.perName)) {
3715
+ cancelRequests.reopen(r);
3716
+ refusals.names++;
3717
+ return cancelReauth(c, code, r, lang, 'too_many');
3718
+ }
3719
+ let proved = null;
3720
+ let outcome = 'unknown';
3721
+ try {
3722
+ proved = await platformSignIn(tag(r.key), account, password, lang);
3723
+ outcome = 'ok';
3724
+ }
3725
+ catch (e) {
3726
+ cancelRequests.reopen(r);
3727
+ outcome = notThere(e) ? 'unknown' : 'failed';
3728
+ logRefused(`[account] a re-sign-in for a cancel link of ${tag(r.key)} refused (${codeOf(e)})`, e);
3729
+ const said = saidBy(e);
3730
+ return said
3731
+ ? cancelReauth(c, code, r, lang, 'sign_in_refused', said)
3732
+ : cancelReauth(c, code, r, lang, notThere(e) ? 'busy' : wrong(e) ? signInFailed : 'sign_in_unconfirmed');
3733
+ }
3734
+ finally {
3735
+ nameFailures.leave(named, outcome);
3736
+ }
3737
+ cancelRequests.reopen(r);
3738
+ const still = store.get(r.key);
3739
+ const sameTok = (p, q) => p.access === q.access || (!!p.mcpToken && p.mcpToken === q.mcpToken);
3740
+ const who = shownOf(proved.session, proved.profile, account);
3741
+ if (!still || still.sid !== r.cancel.sid) {
3742
+ if (!still || !sameTok(proved.session, still.platform))
3743
+ letGoOf(proved.session);
3744
+ return cancelNotOpen(c, code, 'expired', lang);
3745
+ }
3746
+ // ⚠️ ANOTHER ACCOUNT CANCELS NOTHING: a link someone forwarded is refused, and that account's
3747
+ // own sign-in is let go here - never ended at the backend (P2-26).
3748
+ if (who.id !== still.shown.id) {
3749
+ if (!sameTok(proved.session, still.platform))
3750
+ letGoOf(proved.session);
3751
+ log(`[account] a cancel link of ${tag(r.key)} opened by another account: refused`);
3752
+ return cancelReauth(c, code, r, lang, 'reauth_other');
3753
+ }
3754
+ still.platform = proved.session;
3755
+ const id = web.open(r.key, still.sid);
3756
+ if (id)
3757
+ setCookie(c, id);
3758
+ return cancelShown(c, code, r, lang);
3759
+ }
3760
+ const owner = ownerOf(c, r);
3761
+ if (!owner)
3762
+ return cancelReauth(c, code, r, lang);
3763
+ if (body.action !== 'cancel')
3764
+ return send(c, 400, statePage(brandPage, lang, 'checked', cancelHref(code)));
3765
+ const facts = cancelFacts.get(r);
3766
+ if (!facts)
3767
+ return cancelNotOpen(c, code, 'unknown', lang);
3768
+ if (!cancelRequests.begin(r))
3769
+ return cancelNotOpen(c, code, 'pending', lang);
3770
+ // ⚠️ ONE USE, WHATEVER COMES BACK: the link is taken before anything is sent, and stays used - a
3771
+ // second press, a reload or a second tab is shown this outcome, never a second cancel.
3772
+ let done;
3773
+ try {
3774
+ done = await opts.cancels.confirm(r.key, facts);
3775
+ }
3776
+ catch {
3777
+ done = { outcome: 'unknown' };
3778
+ }
3779
+ r.state = 'done';
3780
+ r.doneAt = now();
3781
+ cancelDone.set(r, done);
3782
+ pressed(r.key, r.cancel.sid);
3783
+ log(`[account] cancel on the page k=${tag(r.key)} → ${done.outcome}`);
3784
+ return send(c, 200, cancelDonePage(brandPage, lang, code, done, facts.group));
3785
+ };
3453
3786
  app.get('/account', async (c) => {
3454
3787
  // A group's booking terms, on this same path (0.63.0): told apart by the query.
3455
3788
  const termsCode = c.req.query('terms');
@@ -3459,6 +3792,10 @@ export const makeAccount = (opts) => {
3459
3792
  const addonCode = c.req.query('addon');
3460
3793
  if (addonCode !== undefined)
3461
3794
  return addonGet(c, addonCode);
3795
+ // A booking's cancel (0.84.2, P1-8), likewise.
3796
+ const cancelCode = c.req.query('cancel');
3797
+ if (cancelCode !== undefined)
3798
+ return cancelGet(c, cancelCode);
3462
3799
  const lang = langFor(c);
3463
3800
  if (over(c, 'pages', ipOf(c), ACCOUNT_LIMITS.pagesPerIp))
3464
3801
  return send(c, 429, statePage(brandPage, lang, 'limited', plainHref('/account')));
@@ -3562,6 +3899,9 @@ export const makeAccount = (opts) => {
3562
3899
  // An add-on's confirm (0.82.0): the form's hidden `addon` field.
3563
3900
  if (typeof body.addon === 'string')
3564
3901
  return addonPost(c, body, formStr(body.addon, 64), lang);
3902
+ // A booking's cancel (0.84.2, P1-8): the form's hidden `cancel` field.
3903
+ if (typeof body.cancel === 'string')
3904
+ return cancelPost(c, body, formStr(body.cancel, 64), lang);
3565
3905
  const at = sessionOf(c);
3566
3906
  if (!at.ws || !at.s) {
3567
3907
  if (at.id)
@@ -3614,7 +3954,8 @@ export const makeAccount = (opts) => {
3614
3954
  }
3615
3955
  if (body.action !== 'signout')
3616
3956
  return send(c, 400, statePage(brandPage, lang, 'checked', plainHref('/account')));
3617
- signOut(at.ws.key);
3957
+ if (signOut(at.ws.key))
3958
+ signedOut(at.ws.key);
3618
3959
  web.drop(at.id);
3619
3960
  clearCookie(c);
3620
3961
  log(`[account] ${tag(at.ws.key)} signed out on the account page`);
@@ -3730,6 +4071,7 @@ export const makeAccount = (opts) => {
3730
4071
  requests.cancelFor(key);
3731
4072
  linkRequests.cancelFor(key);
3732
4073
  termsRequests.cancelFor(key);
4074
+ cancelRequests.cancelFor(key);
3733
4075
  if (!was)
3734
4076
  return;
3735
4077
  web.dropFor(was.sid);
@@ -3737,9 +4079,20 @@ export const makeAccount = (opts) => {
3737
4079
  was.links?.clear();
3738
4080
  log(`[account] ${tag(key)}: the backend refused the account's token (401) - signed out here`);
3739
4081
  },
4082
+ // ⚠️ HERE ONLY, NEVER AT THE BACKEND (0.84.2, the 11-25 code audit's P1-8 ②, as P2-26): a take-over
4083
+ // is on the word of whoever holds the trip id - `end` sent a sign-out with no providerCode, and that
4084
+ // ended every channel of the member, in every conversation and group link (the root deployment, where
4085
+ // the guest's own sign-out still does). The pages go, the token is let go here, nothing is sent.
3740
4086
  forget: (key) => {
3741
- if (signOut(key))
3742
- log(`[account] ${tag(key)} signed out: taken over from another network`);
4087
+ const was = store.clear(key);
4088
+ requests.cancelFor(key);
4089
+ linkRequests.cancelFor(key);
4090
+ termsRequests.cancelFor(key);
4091
+ cancelRequests.cancelFor(key);
4092
+ if (!was)
4093
+ return;
4094
+ forgetHere(was, 'taken-over');
4095
+ log(`[account] ${tag(key)} signed out here: taken over from another network`);
3743
4096
  },
3744
4097
  // A linked group's prices are asked for with the conversation's one token (0.72.0):
3745
4098
  // the latest sign-in's, whichever group it was at - a link keeps none of its own.
@@ -3787,6 +4140,7 @@ export const makeAccount = (opts) => {
3787
4140
  bookingAuth,
3788
4141
  termsLink,
3789
4142
  addonLink,
4143
+ cancelLink,
3790
4144
  instructions,
3791
4145
  mount,
3792
4146
  health: () => ({
@@ -3795,6 +4149,7 @@ export const makeAccount = (opts) => {
3795
4149
  accountPages: web.size,
3796
4150
  ...(linking ? { membershipLinksOpen: linkRequests.open() } : {}),
3797
4151
  ...(opts.terms ? { termsLinksOpen: termsRequests.open() } : {}),
4152
+ ...(cancelOn ? { cancelLinksOpen: cancelRequests.open() } : {}),
3798
4153
  ...Object.fromEntries(Object.entries(refusals).map(([k, v]) => [`accountRefused_${k}`, v])),
3799
4154
  }),
3800
4155
  };