@curless/hotel-storefront 0.84.1 → 0.84.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.
Files changed (95) 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 +40 -1
  9. package/dist/account/index.d.ts.map +1 -1
  10. package/dist/account/index.js +376 -33
  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 +12 -5
  24. package/dist/config.d.ts.map +1 -1
  25. package/dist/config.js.map +1 -1
  26. package/dist/otaless/addons-answers.d.ts +2 -0
  27. package/dist/otaless/addons-answers.d.ts.map +1 -1
  28. package/dist/otaless/addons-answers.js +46 -12
  29. package/dist/otaless/addons-answers.js.map +1 -1
  30. package/dist/otaless/addons.d.ts +34 -5
  31. package/dist/otaless/addons.d.ts.map +1 -1
  32. package/dist/otaless/addons.js +150 -47
  33. package/dist/otaless/addons.js.map +1 -1
  34. package/dist/otaless/backend.d.ts.map +1 -1
  35. package/dist/otaless/backend.js +55 -1
  36. package/dist/otaless/backend.js.map +1 -1
  37. package/dist/otaless/booking.d.ts +39 -4
  38. package/dist/otaless/booking.d.ts.map +1 -1
  39. package/dist/otaless/booking.js +406 -61
  40. package/dist/otaless/booking.js.map +1 -1
  41. package/dist/otaless/client.d.ts.map +1 -1
  42. package/dist/otaless/client.js +3 -1
  43. package/dist/otaless/client.js.map +1 -1
  44. package/dist/otaless/fake.d.ts +14 -0
  45. package/dist/otaless/fake.d.ts.map +1 -1
  46. package/dist/otaless/fake.js +18 -8
  47. package/dist/otaless/fake.js.map +1 -1
  48. package/dist/otaless/make.d.ts.map +1 -1
  49. package/dist/otaless/make.js +12 -3
  50. package/dist/otaless/make.js.map +1 -1
  51. package/dist/otaless/shop-answers.d.ts +57 -1
  52. package/dist/otaless/shop-answers.d.ts.map +1 -1
  53. package/dist/otaless/shop-answers.js +115 -12
  54. package/dist/otaless/shop-answers.js.map +1 -1
  55. package/dist/otaless/shop-client.d.ts +7 -0
  56. package/dist/otaless/shop-client.d.ts.map +1 -1
  57. package/dist/otaless/shop-client.js +5 -0
  58. package/dist/otaless/shop-client.js.map +1 -1
  59. package/dist/otaless/shop-fake.d.ts +8 -0
  60. package/dist/otaless/shop-fake.d.ts.map +1 -1
  61. package/dist/otaless/shop-fake.js +5 -3
  62. package/dist/otaless/shop-fake.js.map +1 -1
  63. package/dist/otaless/shop-ids.d.ts +26 -0
  64. package/dist/otaless/shop-ids.d.ts.map +1 -0
  65. package/dist/otaless/shop-ids.js +49 -0
  66. package/dist/otaless/shop-ids.js.map +1 -0
  67. package/dist/otaless/shop-record.d.ts.map +1 -1
  68. package/dist/otaless/shop-record.js +27 -9
  69. package/dist/otaless/shop-record.js.map +1 -1
  70. package/dist/otaless/shop-service.d.ts +85 -21
  71. package/dist/otaless/shop-service.d.ts.map +1 -1
  72. package/dist/otaless/shop-service.js +159 -21
  73. package/dist/otaless/shop-service.js.map +1 -1
  74. package/dist/otaless/shop.d.ts +33 -7
  75. package/dist/otaless/shop.d.ts.map +1 -1
  76. package/dist/otaless/shop.js +76 -27
  77. package/dist/otaless/shop.js.map +1 -1
  78. package/dist/otaless/wallet.d.ts.map +1 -1
  79. package/dist/otaless/wallet.js +27 -6
  80. package/dist/otaless/wallet.js.map +1 -1
  81. package/dist/server.d.ts +1 -1
  82. package/dist/server.d.ts.map +1 -1
  83. package/dist/server.js +77 -6
  84. package/dist/server.js.map +1 -1
  85. package/dist/tools.d.ts +33 -19
  86. package/dist/tools.d.ts.map +1 -1
  87. package/dist/tools.js +368 -27
  88. package/dist/tools.js.map +1 -1
  89. package/dist/trip-ids.d.ts +30 -1
  90. package/dist/trip-ids.d.ts.map +1 -1
  91. package/dist/trip-ids.js +57 -2
  92. package/dist/trip-ids.js.map +1 -1
  93. package/dist/types.d.ts +20 -0
  94. package/dist/types.d.ts.map +1 -1
  95. 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);
@@ -949,6 +968,7 @@ export const makeAccount = (opts) => {
949
968
  requests.cancelFor(key);
950
969
  linkRequests.cancelFor(key);
951
970
  termsRequests.cancelFor(key);
971
+ cancelRequests.cancelFor(key);
952
972
  // The guest's own sign-out: here only where the deployment keeps links (0.82.2), else at the
953
973
  // backend too - every channel of the token.
954
974
  if (was) {
@@ -1142,8 +1162,13 @@ export const makeAccount = (opts) => {
1142
1162
  const walletPart = opts.wallet
1143
1163
  ? makeWalletPart({ wallet: opts.wallet, meta: walletMeta, now, log })
1144
1164
  : undefined;
1145
- /** The account page's wallet block - the page the guest does everything on. */
1146
- 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`;
1147
1172
  const walletCtx = (s, key, ip) => ({
1148
1173
  // The same rows the page and the card show: linked, and not one that needs linking again.
1149
1174
  linkedOf: (group) => {
@@ -1168,8 +1193,12 @@ export const makeAccount = (opts) => {
1168
1193
  ...(linking ? { linkTool: names.link } : {}),
1169
1194
  said: (c) => walletSaid(c, noCards),
1170
1195
  }) ?? '';
1171
- // The account page's link, in words (0.84.0, Lax): the guest's alone to press.
1172
- 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;
1173
1202
  };
1174
1203
  /** An answer with the wallets read now: the same facts in the structure (the card's, the model's) and in the words. */
1175
1204
  const withWallets = async (s, key, answer, lang, noCards, ip) => {
@@ -1561,10 +1590,11 @@ export const makeAccount = (opts) => {
1561
1590
  const ends = Date.parse(c.until);
1562
1591
  if (!Number.isFinite(ends) || ends <= now())
1563
1592
  return undefined;
1564
- 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`.
1565
1596
  const made = addonRequests.create({
1566
1597
  key,
1567
- ...(l ? { lang: l } : {}),
1568
1598
  words: true,
1569
1599
  addon: { ref, sid: s.sid },
1570
1600
  });
@@ -1574,10 +1604,38 @@ export const makeAccount = (opts) => {
1574
1604
  made.request.expires = Math.min(made.request.expires, ends);
1575
1605
  log(`[account] an add-on confirm link for ${tag(key)}`);
1576
1606
  return {
1577
- url: `${publicUrl}/account?addon=${made.code}${l ? `&lang=${l}` : ''}`,
1607
+ url: `${publicUrl}/account?addon=${made.code}`,
1578
1608
  expiresAt: new Date(made.request.expires).toISOString(),
1579
1609
  };
1580
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
+ };
1581
1639
  /**
1582
1640
  * A guest's press on a one-time page (0.84.0, `account.pressCountsAsUse` only): the conversation in use
1583
1641
  * now - see `AccountOptions.onPressed`. Never in a request's way.
@@ -1763,6 +1821,12 @@ export const makeAccount = (opts) => {
1763
1821
  ];
1764
1822
  /** The wallet groups as the descriptions and the words name them. */
1765
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`;
1766
1830
  /** The card tool's wallet properties - only with the switch on (the frozen listing). */
1767
1831
  const walletProps = () => ({
1768
1832
  walletGroup: { type: 'string', enum: [...(walletPart?.groups ?? [])] },
@@ -1807,7 +1871,7 @@ export const makeAccount = (opts) => {
1807
1871
  // That rule is the SERVER INSTRUCTIONS' (`instructions` below, both versions), not this
1808
1872
  // description's (0.75.0, T1: OpenAI - a description says what a tool does, not how the
1809
1873
  // model should use it).
1810
- 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.` : ''}`,
1811
1875
  annotations: {
1812
1876
  title: `My ${brand} account`,
1813
1877
  readOnlyHint: true,
@@ -1876,7 +1940,7 @@ export const makeAccount = (opts) => {
1876
1940
  {
1877
1941
  name: names.card,
1878
1942
  // The card's own (app-only, server.ts): never offered to the assistant.
1879
- 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.` : ''}`,
1880
1944
  annotations: {
1881
1945
  title: `${brand} account (card)`,
1882
1946
  readOnlyHint: false,
@@ -2007,7 +2071,7 @@ export const makeAccount = (opts) => {
2007
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.`
2008
2072
  : '';
2009
2073
  const WALLET_SAID = (noCards) => walletPart
2010
- ? ` ${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.`
2011
2075
  : '';
2012
2076
  const instructions = (noCards) => (noCards
2013
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.'}`
@@ -2108,7 +2172,7 @@ export const makeAccount = (opts) => {
2108
2172
  return at.ws &&
2109
2173
  at.s &&
2110
2174
  at.ws.key === r.key &&
2111
- at.s.sid === (r.link ?? r.terms ?? r.addon)?.sid
2175
+ at.s.sid === (r.link ?? r.terms ?? r.addon ?? r.cancel)?.sid
2112
2176
  ? { id: at.id, s: at.s }
2113
2177
  : null;
2114
2178
  };
@@ -2226,12 +2290,12 @@ export const makeAccount = (opts) => {
2226
2290
  const who = shownOf(proved.session, proved.profile, account);
2227
2291
  if (!still || still.sid !== r.link?.sid) {
2228
2292
  if (!still || !same(proved.session, still.platform))
2229
- void endSession(proved.session);
2293
+ letGoOf(proved.session);
2230
2294
  return notOpen(c, code, 'expired', lang, false);
2231
2295
  }
2232
2296
  if (who.id !== still.shown.id) {
2233
2297
  if (!same(proved.session, still.platform))
2234
- void endSession(proved.session);
2298
+ letGoOf(proved.session);
2235
2299
  log(`[account] a membership link of ${tag(r.key)} opened by another account: refused`);
2236
2300
  return reauthPage(c, code, r, lang, 'reauth_other');
2237
2301
  }
@@ -2467,6 +2531,11 @@ export const makeAccount = (opts) => {
2467
2531
  rooms: t.rooms,
2468
2532
  guests: t.stay.guests,
2469
2533
  total: inFullCurrency(opts.fullCurrency, () => formatMoney(t.total)),
2534
+ ...(t.payAs
2535
+ ? {
2536
+ payAs: inFullCurrency(opts.fullCurrency, () => formatMoney(t.payAs)),
2537
+ }
2538
+ : {}),
2470
2539
  });
2471
2540
  const termsView = (c, code, r, t, lang) => {
2472
2541
  const logo = logoPath(t.group);
@@ -2583,6 +2652,20 @@ export const makeAccount = (opts) => {
2583
2652
  false,
2584
2653
  'failed',
2585
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
+ ],
2586
2669
  'needs-person': [
2587
2670
  '{g}生成了一张和你看到的不一样的单,我们没能取消,已转人工,请不要付款。这张单在对话里的「我的预订」中。',
2588
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.',
@@ -2717,12 +2800,12 @@ export const makeAccount = (opts) => {
2717
2800
  const who = shownOf(proved.session, proved.profile, account);
2718
2801
  if (!still || still.sid !== r.terms.sid) {
2719
2802
  if (!still || !sameTok(proved.session, still.platform))
2720
- void endSession(proved.session);
2803
+ letGoOf(proved.session);
2721
2804
  return termsNotOpen(c, code, 'expired', lang, false);
2722
2805
  }
2723
2806
  if (who.id !== still.shown.id) {
2724
2807
  if (!sameTok(proved.session, still.platform))
2725
- void endSession(proved.session);
2808
+ letGoOf(proved.session);
2726
2809
  log(`[account] a terms link of ${tag(r.key)} opened by another account: refused`);
2727
2810
  return termsReauth(c, code, r, lang, 'reauth_other');
2728
2811
  }
@@ -2803,14 +2886,28 @@ export const makeAccount = (opts) => {
2803
2886
  return send(c, 200, termsResult(r, code, lang, termsErrorDone('terms-gone', lang, groupName, logo)));
2804
2887
  }
2805
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
+ }
2806
2898
  if (view === 'booking' && asStr(booking.hotelName)) {
2807
2899
  const pay = asObj(booking.payment);
2808
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.
2809
2904
  const paid = status === 'paid'
2810
2905
  ? 'paid'
2811
2906
  : status === 'awaiting' || (!status && asStr(pay.url))
2812
2907
  ? 'awaiting'
2813
- : 'confirmed';
2908
+ : booking.paymentUnknown === true
2909
+ ? 'unknown'
2910
+ : 'confirmed';
2814
2911
  const stay = asObj(booking.stay);
2815
2912
  const facts = before
2816
2913
  ? termsFactsOf(before, lang)
@@ -2826,6 +2923,7 @@ export const makeAccount = (opts) => {
2826
2923
  const payByWords = asStr(pay.payByWords);
2827
2924
  const payHost = asStr(pay.host);
2828
2925
  const payAmount = asStr(pay.amount);
2926
+ const quotedAs = asStr(pay.quotedAs);
2829
2927
  const confirmation = asStr(booking.confirmationCode);
2830
2928
  return send(c, 200, termsResult(r, code, lang, {
2831
2929
  kind: 'ordered',
@@ -2839,6 +2937,8 @@ export const makeAccount = (opts) => {
2839
2937
  ...(payByWords ? { payByWords } : {}),
2840
2938
  ...(payUrl ? { payUrl } : {}),
2841
2939
  ...(payAmount ? { payAmount } : {}),
2940
+ ...(quotedAs && payAmount ? { quotedAs } : {}),
2941
+ ...(pay.chargedWhenBooked === true ? { chargedWhenBooked: true } : {}),
2842
2942
  }));
2843
2943
  }
2844
2944
  // A refusal - or a booking that came back with nothing booked.
@@ -3079,25 +3179,27 @@ export const makeAccount = (opts) => {
3079
3179
  if (!s) {
3080
3180
  requests.reopen(r);
3081
3181
  refusals.full++;
3082
- void endSession(got.session);
3182
+ letGoOf(got.session);
3083
3183
  log('[account] a sign-in refused: every place is taken by a live one');
3084
3184
  failed('failed');
3085
3185
  return again('busy');
3086
3186
  }
3087
3187
  requests.done(r);
3088
- // The shop, with the same email and password (0.82.1) - before the page says signed in, so
3089
- // the shop is there when the guest goes back to the chat; never in the account's way.
3090
- await shopWithAccount(r.key, typed, password, lang, {
3091
- tried: up,
3092
- ...(values.nickname ? { name: values.nickname } : {}),
3093
- });
3094
- // 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.
3095
3191
  try {
3096
3192
  opts.onSignedIn?.(r.key, r.codeHash);
3097
3193
  }
3098
3194
  catch {
3099
3195
  log(`[account] ${tag(r.key)}: its trip id was not given out again`);
3100
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
+ });
3101
3203
  usage({
3102
3204
  key: r.key,
3103
3205
  kind: 'account',
@@ -3123,6 +3225,35 @@ export const makeAccount = (opts) => {
3123
3225
  * only `wallet_confirm` with that ticket sends anything. A note on the way back is a short
3124
3226
  * code - no amount, no card digits in the URL.
3125
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
+ };
3126
3257
  const walletPost = async (c, at, body, lang) => {
3127
3258
  const part = walletPart;
3128
3259
  if (!part)
@@ -3140,6 +3271,8 @@ export const makeAccount = (opts) => {
3140
3271
  if (!part.offers(group))
3141
3272
  return send(c, 400, statePage(brandPage, lang, 'checked', plainHref('/account')));
3142
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)}`;
3143
3276
  const cardId = formStr(body.cardId, 64);
3144
3277
  const code = (r) => r.outcome === 'done'
3145
3278
  ? 'done'
@@ -3160,7 +3293,10 @@ export const makeAccount = (opts) => {
3160
3293
  if (act === 'wallet_renew') {
3161
3294
  if (!cardId)
3162
3295
  return back('refused');
3163
- 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);
3164
3300
  }
3165
3301
  // ── Step one: a fresh read, a confirm page, a ticket.
3166
3302
  if (act === 'wallet_review_authorize' ||
@@ -3234,9 +3370,22 @@ export const makeAccount = (opts) => {
3234
3370
  // ── Step two: the ticket is taken (used) before anything is sent.
3235
3371
  if (act === 'wallet_confirm') {
3236
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
+ }
3237
3379
  const t = part.take(owner, ticketCode);
3238
3380
  if (!t)
3239
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';
3240
3389
  // The ticket's own group, whatever the form says.
3241
3390
  const press = ticketCode;
3242
3391
  const r = t.kind === 'authorize'
@@ -3257,9 +3406,8 @@ export const makeAccount = (opts) => {
3257
3406
  })
3258
3407
  : await part.removeCard(ctx, { group: t.group, cardId: t.cardId, press });
3259
3408
  log(`[account] ${tag(at.ws.key)} wallet ${r.action} on the account page: ${r.outcome}${r.reason ? ` (${r.reason})` : ''}`);
3260
- return back(code(r));
3409
+ return code(r);
3261
3410
  }
3262
- return send(c, 400, statePage(brandPage, lang, 'checked', plainHref('/account')));
3263
3411
  };
3264
3412
  // ── An add-on's confirm, on its own page (0.82.0) ──────────────────────────────────────────
3265
3413
  // ⚠️ ON THE EXISTING PATH `/account`, TOLD APART BY ?addon= (Caddy passes fixed paths only).
@@ -3395,12 +3543,12 @@ export const makeAccount = (opts) => {
3395
3543
  const who = shownOf(proved.session, proved.profile, account);
3396
3544
  if (!still || still.sid !== r.addon.sid) {
3397
3545
  if (!still || !sameTok(proved.session, still.platform))
3398
- void endSession(proved.session);
3546
+ letGoOf(proved.session);
3399
3547
  return addonNotOpen(c, code, 'expired', lang);
3400
3548
  }
3401
3549
  if (who.id !== still.shown.id) {
3402
3550
  if (!sameTok(proved.session, still.platform))
3403
- void endSession(proved.session);
3551
+ letGoOf(proved.session);
3404
3552
  log(`[account] an add-on link of ${tag(r.key)} opened by another account: refused`);
3405
3553
  return addonReauth(c, code, r, lang, 'reauth_other');
3406
3554
  }
@@ -3461,6 +3609,180 @@ export const makeAccount = (opts) => {
3461
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' : ''}`);
3462
3610
  return send(c, 200, addonDonePage(brandPage, lang, code, done));
3463
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
+ };
3464
3786
  app.get('/account', async (c) => {
3465
3787
  // A group's booking terms, on this same path (0.63.0): told apart by the query.
3466
3788
  const termsCode = c.req.query('terms');
@@ -3470,6 +3792,10 @@ export const makeAccount = (opts) => {
3470
3792
  const addonCode = c.req.query('addon');
3471
3793
  if (addonCode !== undefined)
3472
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);
3473
3799
  const lang = langFor(c);
3474
3800
  if (over(c, 'pages', ipOf(c), ACCOUNT_LIMITS.pagesPerIp))
3475
3801
  return send(c, 429, statePage(brandPage, lang, 'limited', plainHref('/account')));
@@ -3573,6 +3899,9 @@ export const makeAccount = (opts) => {
3573
3899
  // An add-on's confirm (0.82.0): the form's hidden `addon` field.
3574
3900
  if (typeof body.addon === 'string')
3575
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);
3576
3905
  const at = sessionOf(c);
3577
3906
  if (!at.ws || !at.s) {
3578
3907
  if (at.id)
@@ -3742,6 +4071,7 @@ export const makeAccount = (opts) => {
3742
4071
  requests.cancelFor(key);
3743
4072
  linkRequests.cancelFor(key);
3744
4073
  termsRequests.cancelFor(key);
4074
+ cancelRequests.cancelFor(key);
3745
4075
  if (!was)
3746
4076
  return;
3747
4077
  web.dropFor(was.sid);
@@ -3749,9 +4079,20 @@ export const makeAccount = (opts) => {
3749
4079
  was.links?.clear();
3750
4080
  log(`[account] ${tag(key)}: the backend refused the account's token (401) - signed out here`);
3751
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.
3752
4086
  forget: (key) => {
3753
- if (signOut(key))
3754
- 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`);
3755
4096
  },
3756
4097
  // A linked group's prices are asked for with the conversation's one token (0.72.0):
3757
4098
  // the latest sign-in's, whichever group it was at - a link keeps none of its own.
@@ -3799,6 +4140,7 @@ export const makeAccount = (opts) => {
3799
4140
  bookingAuth,
3800
4141
  termsLink,
3801
4142
  addonLink,
4143
+ cancelLink,
3802
4144
  instructions,
3803
4145
  mount,
3804
4146
  health: () => ({
@@ -3807,6 +4149,7 @@ export const makeAccount = (opts) => {
3807
4149
  accountPages: web.size,
3808
4150
  ...(linking ? { membershipLinksOpen: linkRequests.open() } : {}),
3809
4151
  ...(opts.terms ? { termsLinksOpen: termsRequests.open() } : {}),
4152
+ ...(cancelOn ? { cancelLinksOpen: cancelRequests.open() } : {}),
3810
4153
  ...Object.fromEntries(Object.entries(refusals).map(([k, v]) => [`accountRefused_${k}`, v])),
3811
4154
  }),
3812
4155
  };