@curless/hotel-storefront 0.61.0 → 0.62.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. package/dist/account/fake-ota.d.ts +69 -0
  2. package/dist/account/fake-ota.d.ts.map +1 -0
  3. package/dist/account/fake-ota.js +264 -0
  4. package/dist/account/fake-ota.js.map +1 -0
  5. package/dist/account/index.d.ts +32 -22
  6. package/dist/account/index.d.ts.map +1 -1
  7. package/dist/account/index.js +227 -200
  8. package/dist/account/index.js.map +1 -1
  9. package/dist/account/mask.d.ts +15 -0
  10. package/dist/account/mask.d.ts.map +1 -0
  11. package/dist/account/mask.js +51 -0
  12. package/dist/account/mask.js.map +1 -0
  13. package/dist/account/ota-member.d.ts +106 -11
  14. package/dist/account/ota-member.d.ts.map +1 -1
  15. package/dist/account/ota-member.js +191 -50
  16. package/dist/account/ota-member.js.map +1 -1
  17. package/dist/account/pages.d.ts +13 -2
  18. package/dist/account/pages.d.ts.map +1 -1
  19. package/dist/account/pages.js +34 -10
  20. package/dist/account/pages.js.map +1 -1
  21. package/dist/account/requests.d.ts +1 -1
  22. package/dist/account/requests.js +2 -2
  23. package/dist/account/requests.js.map +1 -1
  24. package/dist/account/said.d.ts +14 -0
  25. package/dist/account/said.d.ts.map +1 -0
  26. package/dist/account/said.js +96 -0
  27. package/dist/account/said.js.map +1 -0
  28. package/dist/account/store.d.ts +16 -15
  29. package/dist/account/store.d.ts.map +1 -1
  30. package/dist/account/store.js +29 -23
  31. package/dist/account/store.js.map +1 -1
  32. package/dist/otaless/backend.d.ts +19 -3
  33. package/dist/otaless/backend.d.ts.map +1 -1
  34. package/dist/otaless/backend.js +51 -20
  35. package/dist/otaless/backend.js.map +1 -1
  36. package/dist/otaless/booking.d.ts +189 -0
  37. package/dist/otaless/booking.d.ts.map +1 -0
  38. package/dist/otaless/booking.js +1227 -0
  39. package/dist/otaless/booking.js.map +1 -0
  40. package/dist/otaless/client.d.ts +180 -0
  41. package/dist/otaless/client.d.ts.map +1 -1
  42. package/dist/otaless/client.js +166 -15
  43. package/dist/otaless/client.js.map +1 -1
  44. package/dist/otaless/fake.d.ts +73 -0
  45. package/dist/otaless/fake.d.ts.map +1 -1
  46. package/dist/otaless/fake.js +270 -2
  47. package/dist/otaless/fake.js.map +1 -1
  48. package/dist/otaless/make.d.ts +2 -0
  49. package/dist/otaless/make.d.ts.map +1 -1
  50. package/dist/otaless/make.js +32 -0
  51. package/dist/otaless/make.js.map +1 -1
  52. package/dist/server.d.ts +1 -1
  53. package/dist/server.d.ts.map +1 -1
  54. package/dist/server.js +4 -1
  55. package/dist/server.js.map +1 -1
  56. package/package.json +1 -1
  57. package/dist/account/fake-mall.d.ts +0 -61
  58. package/dist/account/fake-mall.d.ts.map +0 -1
  59. package/dist/account/fake-mall.js +0 -239
  60. package/dist/account/fake-mall.js.map +0 -1
  61. package/dist/account/mall.d.ts +0 -85
  62. package/dist/account/mall.d.ts.map +0 -1
  63. package/dist/account/mall.js +0 -239
  64. package/dist/account/mall.js.map +0 -1
@@ -1,8 +1,7 @@
1
1
  import { createHmac, randomBytes } from 'node:crypto';
2
2
  import { bodyLimit } from 'hono/body-limit';
3
3
  import { WindowCounter } from '../limits.js';
4
- import { LIMITS, MallError, makeMall, } from './mall.js';
5
- import { OtaMemberError, makeOtaMembers, maskNumber } from './ota-member.js';
4
+ import { LIMITS, OtaMemberError, linkOf, makeOtaMembers, maskNumber, } from './ota-member.js';
6
5
  import { PAGE_HEADERS, accountPage, linkGroupPage, linkReauthPage, linkedPage, loginPage, say, signedInPage, statePage, } from './pages.js';
7
6
  import { CODE, createSignIns, hashOf, same, } from './requests.js';
8
7
  import { AccountStore, WEB_IDLE_MS, WebSessions, shownOf } from './store.js';
@@ -32,8 +31,6 @@ export const ACCOUNT_META_KEY = 'curless/account';
32
31
  export const SIGN_IN_META_KEY = 'curless/account-sign-in';
33
32
  /** …and beside a membership link's answer (0.58.0): the link and its group - no code (0.61.0). */
34
33
  export const LINK_META_KEY = 'curless/account-link';
35
- /** The mall is asked at most this often whether a sign-in is still theirs. */
36
- export const CHECK_EVERY_MS = 5 * 60_000;
37
34
  export const COOKIE = '__Host-hotel_account';
38
35
  /** How many of what, and over how long - each refusal said as "too many requests". */
39
36
  export const ACCOUNT_LIMITS = {
@@ -106,24 +103,6 @@ export const acceptLang = (h) => {
106
103
  }
107
104
  return 'en';
108
105
  };
109
- /**
110
- * A mall failure that says the sign-in is not theirs any more - not a blip on the way.
111
- *
112
- * ⚠️ A NO, NOT EVERY ENVELOPE (0.59.0, review C3). Any envelope that was not 200
113
- * counted - and their envelope says 500 for a fault of their own too (Nexva's
114
- * audit M-18): one 500 on a renewal a minute before the token lapsed signed the
115
- * guest out, and ended their token at the mall. Now only a 4xx - HTTP's or the
116
- * envelope's - is a no: the request was not theirs to grant. A 5xx, a timeout,
117
- * an answer that is not JSON, a code that is not a number, and 408 / 429 (wait
118
- * and ask again) leave them signed in, asked again next time. The refresh
119
- * token's own lapse is the store's (store.ts), not this.
120
- */
121
- export const refused = (e) => e instanceof MallError &&
122
- typeof e.code === 'number' &&
123
- e.code >= 400 &&
124
- e.code < 500 &&
125
- e.code !== 408 &&
126
- e.code !== 429;
127
106
  /**
128
107
  * ⚠️ A POST COMES FROM OUR OWN PAGE (and with the form's token): its Origin is
129
108
  * this site - the public origin, or the Host it was sent to (https; http only
@@ -156,8 +135,8 @@ export const readForm = async (c) => {
156
135
  };
157
136
  /**
158
137
  * ⚠️ A USER NAME'S WRONG GUESSES (review C8, robin 11-09): only a no from the
159
- * mall counts - a sign-in that works clears the name, and a mall that did not
160
- * answer is nobody's mistake. `enter` reserves a try BEFORE the mall is asked
138
+ * backend counts - a sign-in that works clears the name, and a backend that did
139
+ * not answer is nobody's mistake. `enter` reserves a try BEFORE the backend is asked
161
140
  * (it counts the tries still in flight with the failures, so a burst of posts
162
141
  * on many links cannot all pass at "7 of 8"); `leave` settles it. No await sits
163
142
  * between the check and the reservation. Idle names are forgotten first when
@@ -223,17 +202,18 @@ export class NameFailures {
223
202
  }
224
203
  }
225
204
  }
226
- /** How long renewals may go unanswered, the access token lapsed, before the sign-in goes (C3). */
227
- export const RENEW_GIVE_UP_MS = 15 * 60_000;
228
- /** The membership service did not answer - not a no. */
229
- const otaNotThere = (e) => e instanceof OtaMemberError &&
205
+ /**
206
+ * The backend did not answer - not a no: a timeout, no connection, or an HTTP 5xx
207
+ * that is not their envelope's. The only failures a name's wrong tries do not count.
208
+ */
209
+ const notThere = (e) => e instanceof OtaMemberError &&
230
210
  (e.code === 'timeout' ||
231
211
  e.code === 'unreachable' ||
232
212
  (typeof e.code === 'number' && e.code >= 500 && !e.envelope));
233
213
  /**
234
214
  * The backend answered and said no to the credentials (0.59.1, robin 11-09,
235
215
  * questions #49): an HTTP 4xx, or its envelope's own no (`code: 500` in an HTTP
236
- * 200 is its "wrong", as the mall's). The only answers that are the guest's
216
+ * 200 is its "wrong"). The only answers that are the guest's
237
217
  * mistake for certain - the only ones the page says "the password" for. A
238
218
  * `form`, `not_signed_in`, `wrong_group` or `not_json` is the backend not
239
219
  * confirming (the dev backend answers a form for a good password): the page
@@ -243,16 +223,13 @@ const otaNotThere = (e) => e instanceof OtaMemberError &&
243
223
  * review of 0.60.1): a backend may well say "wrong password" with a form one
244
224
  * day - Spark's shops answer a form to everything now - and an uncounted form
245
225
  * would make this page a way to guess a group member's password, eight at a
246
- * time no more. Only no answer at all (`otaNotThere`) is not counted.
226
+ * time no more. Only no answer at all (`notThere`) is not counted.
247
227
  */
248
- const otaWrong = (e) => e instanceof OtaMemberError &&
228
+ const wrong = (e) => e instanceof OtaMemberError &&
249
229
  typeof e.code === 'number' &&
250
230
  ((e.code >= 400 && e.code < 500) || e.envelope);
251
- /** The mall did not answer - not a no. */
252
- const notThere = (e) => e instanceof MallError &&
253
- (e.code === 'timeout' ||
254
- e.code === 'unreachable' ||
255
- (typeof e.code === 'number' && e.code >= 500 && !e.envelope));
231
+ /** What the backend said for its no, cleaned (said.ts) - undefined when it said nothing. */
232
+ const saidBy = (e) => e instanceof OtaMemberError ? e.said : undefined;
256
233
  export const makeAccount = (opts) => {
257
234
  const now = opts.now ?? (() => Date.now());
258
235
  const env = opts.env ?? process.env;
@@ -260,8 +237,21 @@ export const makeAccount = (opts) => {
260
237
  const baseUrl = env[`${prefix}_API_URL`] || opts.account.baseUrl;
261
238
  const tenant = env[`${prefix}_TENANT_ID`] || opts.account.tenant;
262
239
  if (!baseUrl || !tenant)
263
- throw new Error(`account: no mall address or tenant (account.baseUrl / account.tenant, or ${prefix}_API_URL / ${prefix}_TENANT_ID)`);
264
- const mall = makeMall({
240
+ throw new Error(`account: no backend address or tenant (account.baseUrl / account.tenant, or ${prefix}_API_URL / ${prefix}_TENANT_ID)`);
241
+ // ⚠️ ONE KIND OF ACCOUNT (0.62.0): the mall's (`source: 'mall'`) is gone, and a
242
+ // config still naming it is a mistake to stop on, not to guess past.
243
+ if (opts.account.source !== 'ota')
244
+ throw new Error(`account: source must be "ota" (the backend's /api/v1/ota/*), not ${JSON.stringify(opts.account.source)}`);
245
+ // The channel the account signs in on - see the top of this file (questions #50).
246
+ const signInProvider = (env[`${prefix}_SIGN_IN_PROVIDER`] ||
247
+ opts.account.signInProvider ||
248
+ 'ascott')
249
+ .trim()
250
+ .toLowerCase();
251
+ if (!/^[a-z0-9_-]{1,32}$/.test(signInProvider))
252
+ throw new Error('account: signInProvider is not a channel code');
253
+ // The backend's `/ota/*`: the account's own sign-in, and its hotel memberships'.
254
+ const ota = makeOtaMembers({
265
255
  baseUrl,
266
256
  tenant,
267
257
  ...(opts.fetch ? { fetch: opts.fetch } : {}),
@@ -270,8 +260,8 @@ export const makeAccount = (opts) => {
270
260
  const log = opts.log ?? ((l) => console.log(l));
271
261
  const names = accountToolNames(opts.prefix);
272
262
  const requests = createSignIns({ now });
273
- // A sign-in forgotten here - left two hours, past its tokens, or pushed out -
274
- // is ended at the mall too (review P3-3).
263
+ // A sign-in forgotten here - left two hours, past its session, or pushed out -
264
+ // is ended at the backend too (review P3-3).
275
265
  const store = new AccountStore(now, (s) => end(s));
276
266
  const web = new WebSessions(now);
277
267
  // The form's token, from a secret of this process: a restart voids open
@@ -351,12 +341,6 @@ export const makeAccount = (opts) => {
351
341
  return undefined;
352
342
  }
353
343
  };
354
- const ota = makeOtaMembers({
355
- baseUrl,
356
- tenant,
357
- ...(opts.fetch ? { fetch: opts.fetch } : {}),
358
- now,
359
- });
360
344
  // A request table of their own: a link used does not void the account's sign-in links.
361
345
  const linkRequests = createSignIns({ now });
362
346
  const linkCsrf = (r) => createHmac('sha256', secretKey).update(`link:${r.codeHash}`).digest('base64url').slice(0, 32);
@@ -370,17 +354,26 @@ export const makeAccount = (opts) => {
370
354
  s.links?.delete(code);
371
355
  return undefined;
372
356
  };
373
- /** Unlinked: forgotten here, and the group's session ended at the backend (not waited for). */
374
- const unlink = (s, code) => {
357
+ /**
358
+ * Unlinked: forgotten here, and the group's session ended at the backend - the
359
+ * promise of that, or null where there was no link.
360
+ *
361
+ * ⚠️ NOT THE ACCOUNT'S OWN CHANNEL SESSION: a group linked on the channel the
362
+ * account signed in on may come back with the account's own `mcpToken` (one
363
+ * local session, their document) - ending it would end the account's too.
364
+ */
365
+ const dropLink = (s, code) => {
375
366
  const l = s.links?.get(code);
376
367
  if (!l)
377
- return false;
368
+ return null;
378
369
  s.links?.delete(code);
379
- ota
380
- .signOut({ group: code, ...(l.session ? { session: l.session } : {}), auth: s.tokens.access })
370
+ if (l.session && l.session === s.platform.mcpToken)
371
+ return Promise.resolve();
372
+ return ota
373
+ .signOut({ group: code, ...(l.session ? { session: l.session } : {}), auth: l.token })
381
374
  .catch((e) => log(`[account] a membership's sign-out did not answer (${codeOf(e)})`));
382
- return true;
383
375
  };
376
+ const unlink = (s, code) => dropLink(s, code) !== null;
384
377
  /** "ASR Member (AS82••36)" → "ASR Member": a label with its hidden number taken out. */
385
378
  const tierOf = (label) => label
386
379
  .replace(/\s*[([(][^)\])]*••[^)\])]*[)\])]/g, '')
@@ -434,22 +427,31 @@ export const makeAccount = (opts) => {
434
427
  };
435
428
  // ── Signing in and out ───────────────────────────────────────────────────
436
429
  /** Signed in now, for this conversation: whatever was there before is ended. */
437
- const signInWith = (key, member, tokens) => {
430
+ const signInWith = (key, shown, platform) => {
438
431
  const was = store.clear(key);
439
432
  if (was)
440
433
  end(was);
441
434
  requests.cancelFor(key);
442
435
  linkRequests.cancelFor(key);
443
- return store.set(key, member, tokens);
436
+ return store.set(key, shown, platform);
444
437
  };
445
- /** A sign-in that is over: its pages closed, its tokens ended at the mall (not waited for). */
438
+ /** A channel session of the account's own, ended at the backend (not waited for). */
439
+ const endSession = (p) => ota
440
+ .signOut({
441
+ group: p.provider,
442
+ ...(p.mcpToken ? { session: p.mcpToken } : {}),
443
+ auth: p.access,
444
+ })
445
+ .catch((e) => log(`[account] the backend's sign-out did not answer (${codeOf(e)})`));
446
+ /**
447
+ * A sign-in that is over: its pages closed, its memberships unlinked, its session
448
+ * ended at the backend (not waited for) - ⚠️ THE MEMBERSHIPS FIRST: they share the
449
+ * account's local session (their document), so it is ended only after theirs.
450
+ */
446
451
  const end = (s) => {
447
452
  web.dropFor(s.sid);
448
- for (const code of [...(s.links?.keys() ?? [])])
449
- unlink(s, code);
450
- mall
451
- .logout(s.tokens)
452
- .catch((e) => log(`[account] the mall's sign-out did not answer (${codeOf(e)})`));
453
+ const links = [...(s.links?.keys() ?? [])].map((code) => dropLink(s, code));
454
+ void Promise.allSettled(links).then(() => endSession(s.platform));
453
455
  };
454
456
  const signOut = (key) => {
455
457
  const was = store.clear(key);
@@ -459,92 +461,21 @@ export const makeAccount = (opts) => {
459
461
  end(was);
460
462
  return was;
461
463
  };
462
- const codeOf = (e) => e instanceof MallError || e instanceof OtaMemberError
463
- ? String(e.code).slice(0, 16)
464
+ // The code, and the backend's own words for it where it gave any (0.61.1,
465
+ // questions #55): `refused (500: Password cannot be empty)`. `said` is
466
+ // already clean (said.ts): one line, 120 characters, nothing of ours in it.
467
+ const codeOf = (e) => e instanceof OtaMemberError
468
+ ? `${String(e.code).slice(0, 16)}${e.said ? `: ${e.said}` : ''}`
464
469
  : e instanceof Error
465
470
  ? e.name
466
471
  : 'error';
467
472
  /**
468
- * Still theirs? Asked of the mall at most every five minutes: a token
469
- * revoked there - signed out on another device - answers as nobody, and the
470
- * sign-in here goes. A blip on the way is not that: kept, asked next time.
473
+ * The conversation's sign-in, while its session stands. ⚠️ NOTHING TO ASK THE
474
+ * BACKEND ANY MORE (0.62.0): their `/ota/*` has no /member/info and no refresh
475
+ * token (「本接口已彻底弃用 refreshToken」) - a sign-in lasts its `expireIn`,
476
+ * held to our own day (`MAX_SESSION_S`), and two idle hours (store.ts).
471
477
  */
472
- // ⚠️ ONE LOOK AT A TIME FOR A CONVERSATION (review P3-5): two at once spent
473
- // the same refresh token, and the mall, rotating it, refused the second -
474
- // read as signed out.
475
- const looking = new Map();
476
- const checked = (key) => {
477
- const s = store.get(key);
478
- if (!s || now() - s.checkedAt < CHECK_EVERY_MS)
479
- return Promise.resolve(s);
480
- const out = looking.get(key);
481
- if (out)
482
- return out;
483
- const p = look(key, s).finally(() => looking.delete(key));
484
- looking.set(key, p);
485
- return p;
486
- };
487
- const look = async (key, s) => {
488
- // ⚠️ ONLY A REFUSED RENEWAL, OR A TOKEN THE MALL SAYS IS NOBODY'S, SIGNS OUT:
489
- // their envelope says 500 for a fault of theirs too (Nexva's audit M-18).
490
- const GONE = new Error('gone');
491
- const renew = async () => {
492
- try {
493
- s.tokens = await mall.refresh(s.tokens);
494
- s.renewFailingSince = undefined;
495
- }
496
- catch (e) {
497
- if (refused(e))
498
- throw GONE;
499
- // ⚠️ A BLIP IS SHORT (0.59.0, review C3). The mall's envelope says 500
500
- // for "no valid buyer" too (apidev, 10-20) - so a 500 here may be a dead
501
- // refresh token, and kept as a blip it would show the guest signed in
502
- // for good. Once the access token has lapsed and no renewal has been
503
- // answered for a quarter of an hour, the sign-in is no use to anyone:
504
- // it goes, as a refused one does.
505
- const since = s.renewFailingSince ?? now();
506
- s.renewFailingSince = since;
507
- if (s.tokens.accessExpires <= now() && now() - since >= RENEW_GIVE_UP_MS)
508
- throw GONE;
509
- throw e;
510
- }
511
- };
512
- const whoIs = () => mall.info(s.tokens).catch((e) => {
513
- if (e instanceof MallError && (e.code === 401 || e.code === 403))
514
- return null;
515
- throw e;
516
- });
517
- try {
518
- if (s.tokens.accessExpires - now() < 60_000)
519
- await renew();
520
- let who = await whoIs();
521
- if (!who || who.id !== s.shown.id) {
522
- await renew();
523
- who = await whoIs();
524
- }
525
- if (!who || who.id !== s.shown.id)
526
- throw GONE;
527
- s.shown = shownOf(who);
528
- s.checkedAt = now();
529
- return s;
530
- }
531
- catch (e) {
532
- // ⚠️ ONLY THE SIGN-IN THIS LOOK WAS FOR (re-review P3-2): signed out and in
533
- // again while the mall kept it waiting, the conversation has a new one,
534
- // which an old token's refusal says nothing about.
535
- const nowIn = store.get(key);
536
- if (nowIn?.sid !== s.sid)
537
- return nowIn;
538
- if (e === GONE) {
539
- log(`[account] ${tag(key)} is not signed in at the mall any more: signed out here`);
540
- signOut(key);
541
- return undefined;
542
- }
543
- // Not now: the sign-in stands, and is asked about again next time.
544
- log(`[account] ${tag(key)}: the mall could not be asked (${codeOf(e)}) - still signed in`);
545
- return nowIn;
546
- }
547
- };
478
+ const checked = (key) => store.get(key);
548
479
  // ── The tools ────────────────────────────────────────────────────────────
549
480
  const NO_PRICE = linking
550
481
  ? `Being signed in to ${brand} itself changes no price or room shown here; a hotel group's membership linked to the account (${names.link}) asks that group for its prices as the member.`
@@ -563,7 +494,7 @@ export const makeAccount = (opts) => {
563
494
  const shownFor = (s) => (nameOf(s) ? { displayName: nameOf(s) } : {});
564
495
  const whoSaid = (s) => nameOf(s) ? `the ${brand} account of ${nameOf(s)}` : `${aBrand} account`;
565
496
  const signedInAnswer = (s, lead, noCards) => ({
566
- text: `${lead} Signed in to ${whoSaid(s)}. ${linking ? '' : `${NO_PRICE} `}The guest sees the whole account - its user name, and its email and phone partly hidden - on ${brand}'s account page, ${accountUrl}, in the browser they signed in with, for ${WEB_IDLE_MS / 60_000} minutes after. ${names.signOut} signs them out.${linking ? ` ${membershipsSaid(s, noCards)}` : ''}`.trim(),
497
+ text: `${lead} Signed in to ${whoSaid(s)}. ${linking ? '' : `${NO_PRICE} `}The guest sees the whole account - its user name, and its email partly hidden - on ${brand}'s account page, ${accountUrl}, in the browser they signed in with, for ${WEB_IDLE_MS / 60_000} minutes after. ${names.signOut} signs them out.${linking ? ` ${membershipsSaid(s, noCards)}` : ''}`.trim(),
567
498
  structured: {
568
499
  view: 'account',
569
500
  brand,
@@ -591,7 +522,7 @@ export const makeAccount = (opts) => {
591
522
  isError: true,
592
523
  };
593
524
  const g = groupSaid(m, noCards);
594
- const s = await checked(key);
525
+ const s = checked(key);
595
526
  if (!s)
596
527
  return {
597
528
  text: `Linking a ${g} membership needs the guest signed in to ${aBrand} account first: ${names.signIn} gives them a one-time page for that. ${NEVER_IN_CHAT[0]?.toUpperCase()}${NEVER_IN_CHAT.slice(1)}.`,
@@ -707,7 +638,7 @@ export const makeAccount = (opts) => {
707
638
  return linkAnswer(args, call);
708
639
  }
709
640
  if (name === names.view) {
710
- const s = await checked(key);
641
+ const s = checked(key);
711
642
  if (s)
712
643
  return signedInAnswer(s, '', noCards);
713
644
  const waiting = requests.openFor(key);
@@ -755,7 +686,7 @@ export const makeAccount = (opts) => {
755
686
  }
756
687
  if (name !== names.signIn)
757
688
  throw new Error(`not an account tool: ${name}`);
758
- const s = await checked(key);
689
+ const s = checked(key);
759
690
  if (s)
760
691
  return {
761
692
  ...signedInAnswer(s, '', noCards),
@@ -1132,7 +1063,7 @@ export const makeAccount = (opts) => {
1132
1063
  ? { id: at.id, s: at.s }
1133
1064
  : null;
1134
1065
  };
1135
- const groupPage = (c, code, r, s, lang, mode, error, values) => {
1066
+ const groupPage = (c, code, r, s, lang, mode, error, values, said) => {
1136
1067
  const m = groupOf(r.link?.group);
1137
1068
  return send(c, 200, linkGroupPage(brandPage, {
1138
1069
  lang,
@@ -1145,10 +1076,11 @@ export const makeAccount = (opts) => {
1145
1076
  accountName: nameOf(s),
1146
1077
  mode: mode === 'up' && m?.join === true ? 'up' : 'in',
1147
1078
  ...(error ? { error: say(lang, error, m ? groupIn(m, lang) : brand) } : {}),
1079
+ ...(error && said ? { said } : {}),
1148
1080
  ...(values ? { values } : {}),
1149
1081
  }));
1150
1082
  };
1151
- const reauthPage = (c, code, r, lang, error) => {
1083
+ const reauthPage = (c, code, r, lang, error, said) => {
1152
1084
  const m = groupOf(r.link?.group);
1153
1085
  return send(c, 200, linkReauthPage(brandPage, {
1154
1086
  lang,
@@ -1157,6 +1089,7 @@ export const makeAccount = (opts) => {
1157
1089
  group: m ? groupIn(m, lang) : String(r.link?.group),
1158
1090
  ...(m && logoPath(m.code) ? { logo: logoPath(m.code) } : {}),
1159
1091
  ...(error ? { error: say(lang, error, brand) } : {}),
1092
+ ...(error && said ? { said } : {}),
1160
1093
  }));
1161
1094
  };
1162
1095
  const linkGet = (c, code, r) => {
@@ -1197,7 +1130,7 @@ export const makeAccount = (opts) => {
1197
1130
  if (!account || !password)
1198
1131
  return reauthPage(c, code, r, lang, 'missing_in');
1199
1132
  // ⚠️ COUNTED AS A SIGN-IN OF THE ACCOUNT IS (总线程 11-06): by the name -
1200
- // the SAME `nameFailures` as the sign-in page (C8: only a no from the mall
1133
+ // the SAME `nameFailures` as the sign-in page (C8: only a no from the backend
1201
1134
  // counts, a success clears the name) - and for everyone.
1202
1135
  const named = `a:${account.toLowerCase()}`;
1203
1136
  if (nameFailures.shut(named, ACCOUNT_LIMITS.perName)) {
@@ -1216,29 +1149,47 @@ export const makeAccount = (opts) => {
1216
1149
  let proved = null;
1217
1150
  let triedOutcome = 'unknown';
1218
1151
  try {
1219
- proved = await mall.login({ account, password });
1152
+ proved = await ota.signIn({ group: signInProvider, identity: account, password, lang });
1220
1153
  triedOutcome = 'ok';
1221
1154
  }
1222
1155
  catch (e) {
1223
1156
  linkRequests.reopen(r);
1224
1157
  triedOutcome = notThere(e) ? 'unknown' : 'failed';
1225
1158
  log(`[account] a re-sign-in for a membership link of ${tag(r.key)} refused (${codeOf(e)})`);
1226
- return reauthPage(c, code, r, lang, notThere(e) ? 'busy' : 'sign_in_failed');
1159
+ const said = saidBy(e);
1160
+ return said
1161
+ ? reauthPage(c, code, r, lang, 'sign_in_refused', said)
1162
+ : reauthPage(c, code, r, lang, notThere(e) ? 'busy' : wrong(e) ? 'sign_in_failed' : 'sign_in_unconfirmed');
1227
1163
  }
1228
1164
  finally {
1229
1165
  nameFailures.leave(named, triedOutcome);
1230
1166
  }
1231
1167
  linkRequests.reopen(r);
1232
- // Only to prove who: its tokens are ended at once - the account's own sign-in stands.
1233
- mall.logout(proved.tokens).catch(() => { });
1234
1168
  const still = store.get(r.key);
1235
- if (!still || still.sid !== r.link?.sid)
1169
+ const same = (p, q) => p.access === q.access || (!!p.mcpToken && p.mcpToken === q.mcpToken);
1170
+ // ⚠️ ANOTHER ACCOUNT: refused, its session ended, and nothing of the link's
1171
+ // account said (总线程 11-06 (b)) - by their member_user id AND user name
1172
+ // (store.ts `shownOf`).
1173
+ const who = shownOf(proved.session, proved.profile, account);
1174
+ if (!still || still.sid !== r.link?.sid) {
1175
+ if (!still || !same(proved.session, still.platform))
1176
+ void endSession(proved.session);
1236
1177
  return notOpen(c, code, 'expired', lang, false);
1237
- // ⚠️ ANOTHER ACCOUNT: refused, and nothing of the link's account said (总线程 11-06 (b)).
1238
- if (!proved.member || proved.member.id !== still.shown.id) {
1178
+ }
1179
+ if (who.id !== still.shown.id) {
1180
+ if (!same(proved.session, still.platform))
1181
+ void endSession(proved.session);
1239
1182
  log(`[account] a membership link of ${tag(r.key)} opened by another account: refused`);
1240
1183
  return reauthPage(c, code, r, lang, 'reauth_other');
1241
1184
  }
1185
+ // ⚠️ THE SAME ACCOUNT: ITS NEWER SESSION IS KEPT, NOT ENDED (0.62.0). Their
1186
+ // document keeps one local session for a member's sign-ins - ending this
1187
+ // one could end the account's own. The older is ended only where it shares
1188
+ // neither token with the newer.
1189
+ const older = still.platform;
1190
+ still.platform = proved.session;
1191
+ if (!same(older, proved.session))
1192
+ void endSession(older);
1242
1193
  const id = web.open(r.key, still.sid);
1243
1194
  if (id)
1244
1195
  setCookie(c, id);
@@ -1256,7 +1207,7 @@ export const makeAccount = (opts) => {
1256
1207
  phone: formStr(body.phone, LIMITS.mobile).trim(),
1257
1208
  }
1258
1209
  : { identity: formStr(body.identity, 120).trim() };
1259
- const again = (error, as = up ? 'up' : 'in', kept = values) => groupPage(c, code, r, owner.s, lang, as, error, kept);
1210
+ const again = (error, as = up ? 'up' : 'in', kept = values, said) => groupPage(c, code, r, owner.s, lang, as, error, kept, said);
1260
1211
  const phone = (values.phone ?? '').replace(/[\s().-]/g, '');
1261
1212
  if (up) {
1262
1213
  if (!values.name || !values.email || !password)
@@ -1287,7 +1238,7 @@ export const makeAccount = (opts) => {
1287
1238
  }
1288
1239
  let outcome = 'unknown';
1289
1240
  try {
1290
- const auth = owner.s.tokens.access;
1241
+ const auth = owner.s.platform.access;
1291
1242
  let memberNo;
1292
1243
  if (up) {
1293
1244
  try {
@@ -1302,27 +1253,39 @@ export const makeAccount = (opts) => {
1302
1253
  }
1303
1254
  catch (e) {
1304
1255
  linkRequests.reopen(r);
1305
- outcome = otaNotThere(e) ? 'unknown' : 'failed';
1256
+ outcome = notThere(e) ? 'unknown' : 'failed';
1306
1257
  log(`[account] a membership for ${tag(r.key)} refused (${codeOf(e)})`);
1307
- return again(otaNotThere(e) ? 'link_busy' : 'join_failed');
1258
+ const said = saidBy(e);
1259
+ if (said)
1260
+ return again('join_refused', 'up', values, said);
1261
+ return again(notThere(e) ? 'link_busy' : 'join_failed');
1308
1262
  }
1309
1263
  }
1310
1264
  let link;
1311
1265
  try {
1312
- link = await ota.signIn({
1266
+ const got = await ota.signIn({
1313
1267
  group: m.code,
1314
1268
  identity: (up ? values.email : values.identity) ?? '',
1315
1269
  password,
1316
1270
  auth,
1271
+ lang,
1317
1272
  });
1273
+ // ⚠️ A LINK NEEDS THE GROUP'S OWN SESSION TOKEN (questions #48, as 0.58.0):
1274
+ // without one there is nothing of the group's to sign out of, or book with.
1275
+ if (!got.session.mcpToken)
1276
+ throw new OtaMemberError('not_signed_in');
1277
+ link = linkOf(m.code, got.session, got.profile, now());
1318
1278
  }
1319
1279
  catch (e) {
1320
1280
  linkRequests.reopen(r);
1321
- outcome = otaNotThere(e) ? 'unknown' : 'failed';
1281
+ outcome = notThere(e) ? 'unknown' : 'failed';
1322
1282
  log(`[account] a membership link for ${tag(r.key)} refused (${codeOf(e)})`);
1283
+ const said = saidBy(e);
1323
1284
  if (up)
1324
- return again('joined_not_linked', 'in', { identity: values.email ?? '' });
1325
- return again(otaNotThere(e) ? 'link_busy' : otaWrong(e) ? 'link_failed' : 'link_unconfirmed');
1285
+ return again('joined_not_linked', 'in', { identity: values.email ?? '' }, said);
1286
+ if (said)
1287
+ return again('link_refused', 'in', values, said);
1288
+ return again(notThere(e) ? 'link_busy' : wrong(e) ? 'link_failed' : 'link_unconfirmed');
1326
1289
  }
1327
1290
  outcome = 'ok';
1328
1291
  // Still that sign-in, after the backend kept us waiting?
@@ -1330,17 +1293,30 @@ export const makeAccount = (opts) => {
1330
1293
  if (!now2 || now2.sid !== r.link?.sid) {
1331
1294
  linkRequests.reopen(r);
1332
1295
  ota
1333
- .signOut({ group: m.code, ...(link.session ? { session: link.session } : {}), auth })
1296
+ .signOut({
1297
+ group: m.code,
1298
+ ...(link.session ? { session: link.session } : {}),
1299
+ auth: link.token,
1300
+ })
1334
1301
  .catch(() => { });
1335
1302
  return notOpen(c, code, 'expired', lang, false);
1336
1303
  }
1337
1304
  if (memberNo)
1338
1305
  link.numberMasked = maskNumber(memberNo);
1306
+ // A link there already is replaced - its session ended only where it is not
1307
+ // the one just signed in (one session, their document).
1339
1308
  const was = now2.links?.get(m.code);
1340
- if (was)
1309
+ if (was?.session && was.session === link.session)
1310
+ now2.links?.delete(m.code);
1311
+ else if (was)
1341
1312
  unlink(now2, m.code);
1342
1313
  now2.links ??= new Map();
1343
1314
  now2.links.set(m.code, link);
1315
+ // ⚠️ ONE LOCAL SESSION, AT ITS LONGEST (their document: several channels'
1316
+ // sign-ins share the account's session, renewed to the longest): where the
1317
+ // group came back with the account's own token, the account lasts as long.
1318
+ if (link.token === now2.platform.access && link.expires > now2.platform.expires)
1319
+ now2.platform.expires = link.expires;
1344
1320
  linkRequests.done(r);
1345
1321
  log(`[account] ${tag(r.key)} linked a ${m.code} membership${up ? ' it made' : ''}`);
1346
1322
  return send(c, 200, linkedPage(brandPage, {
@@ -1413,7 +1389,7 @@ export const makeAccount = (opts) => {
1413
1389
  }
1414
1390
  : { account: formStr(body.account, LIMITS.account).trim() };
1415
1391
  const password = formStr(body.password, LIMITS.password);
1416
- const again = (error, as = up ? 'up' : 'in', kept = values) => send(c, 200, loginPage(brandPage, {
1392
+ const again = (error, as = up ? 'up' : 'in', kept = values, said) => send(c, 200, loginPage(brandPage, {
1417
1393
  lang,
1418
1394
  short: r.short,
1419
1395
  code,
@@ -1422,8 +1398,9 @@ export const makeAccount = (opts) => {
1422
1398
  form: as,
1423
1399
  values: kept,
1424
1400
  error: errorOf(lang, error),
1401
+ ...(said ? { said } : {}),
1425
1402
  }));
1426
- // What the form itself can tell, without asking the mall.
1403
+ // What the form itself can tell, without asking the backend.
1427
1404
  const mobile = (values.mobile ?? '').replace(/[\s().-]/g, '');
1428
1405
  if (up) {
1429
1406
  if (!values.userName || !values.email || !password)
@@ -1438,7 +1415,7 @@ export const makeAccount = (opts) => {
1438
1415
  else if (!values.account || !password)
1439
1416
  return again('missing_in');
1440
1417
  // ⚠️ BY THE NAME TOO (Nexva's member_sign_in): one user name's WRONG
1441
- // guesses, from however many links and addresses. Only a no from the mall
1418
+ // guesses, from however many links and addresses. Only a no from the backend
1442
1419
  // counts (C8, robin 11-09); the check here is a look, the try is reserved
1443
1420
  // below once nothing else can turn this post away.
1444
1421
  const who = `${up ? 'r' : 'a'}:${(up ? values.userName : values.account)?.toLowerCase()}`;
@@ -1462,37 +1439,50 @@ export const makeAccount = (opts) => {
1462
1439
  return again('too_many');
1463
1440
  }
1464
1441
  let outcome = 'unknown';
1465
- let tokens;
1466
- let member;
1442
+ let got;
1443
+ let typed = values.account ?? '';
1467
1444
  try {
1468
1445
  if (up) {
1446
+ let channels;
1469
1447
  try {
1470
- await mall.register({
1448
+ // ⚠️ EVERY CHANNEL AT ONCE (their 聚合模式, total thread 11-10): no
1449
+ // providerCode - the backend opens the account on each channel it has on,
1450
+ // and its own member_user beside.
1451
+ ({ channels } = await ota.registerAccount({
1471
1452
  userName: values.userName ?? '',
1472
1453
  email: values.email ?? '',
1473
1454
  password,
1474
- ...(mobile ? { mobile } : {}),
1475
- ...(values.nickname ? { nickname: values.nickname } : {}),
1476
- });
1455
+ ...(values.nickname ? { name: values.nickname } : {}),
1456
+ ...(mobile ? { phone: mobile } : {}),
1457
+ lang,
1458
+ }));
1477
1459
  }
1478
1460
  catch (e) {
1479
1461
  requests.reopen(r);
1480
1462
  outcome = notThere(e) ? 'unknown' : 'failed';
1481
1463
  log(`[account] an account for ${tag(r.key)} refused (${codeOf(e)})`);
1464
+ const said = saidBy(e);
1465
+ if (said)
1466
+ return again('register_refused', 'up', values, said);
1482
1467
  return again(notThere(e) ? 'busy' : 'register_failed');
1483
1468
  }
1484
1469
  outcome = 'ok';
1470
+ // Each channel by its code and whether it took the account - nothing of the guest's.
1471
+ log(`[account] an account was made for ${tag(r.key)} (channels: ${channels.map((x) => `${x.code} ${x.ok ? 'ok' : 'no'}`).join(', ') || 'none said'})`);
1472
+ // Signed in by the EMAIL: the channel it signs in on takes one (Ascott's own
1473
+ // sign-in asks for `identity_field: email`, questions #48).
1474
+ typed = values.email ?? '';
1485
1475
  try {
1486
- ({ tokens, member } = await mall.login({ account: values.userName ?? '', password }));
1476
+ got = await ota.signIn({ group: signInProvider, identity: typed, password, lang });
1487
1477
  }
1488
1478
  catch (e) {
1489
1479
  requests.reopen(r);
1490
1480
  log(`[account] an account was made for ${tag(r.key)}; signing in refused (${codeOf(e)})`);
1491
- return again('registered_not_signed_in', 'in', { account: values.userName ?? '' });
1481
+ return again('registered_not_signed_in', 'in', { account: typed }, saidBy(e));
1492
1482
  }
1493
1483
  }
1494
1484
  else {
1495
- ({ tokens, member } = await mall.login({ account: values.account ?? '', password }));
1485
+ got = await ota.signIn({ group: signInProvider, identity: typed, password, lang });
1496
1486
  outcome = 'ok';
1497
1487
  }
1498
1488
  }
@@ -1500,29 +1490,30 @@ export const makeAccount = (opts) => {
1500
1490
  requests.reopen(r);
1501
1491
  outcome = notThere(e) ? 'unknown' : 'failed';
1502
1492
  log(`[account] a sign-in for ${tag(r.key)} refused (${codeOf(e)})`);
1503
- // ⚠️ OUR WORDS, NOT THE MALL'S (Nexva's review P3): theirs told a taken
1504
- // user name from a wrong password - a way to probe for accounts.
1505
- return again(notThere(e) ? 'busy' : 'sign_in_failed');
1493
+ // ⚠️ THE BACKEND'S OWN WORDS, UNDER A LINE OF OURS THAT GUESSES NOTHING
1494
+ // (0.61.1, robin: 供应方原文照原样显示; questions #55 - every no is their
1495
+ // 500, and our guess 「用户名或密码不对」 was as likely wrong). Nexva's
1496
+ // review P3 kept them off the page because they can tell a taken user name
1497
+ // from a wrong password; what still bounds that probe is the per-name
1498
+ // count above and the sign-ins-per-minute for everyone. No words from
1499
+ // them (a timeout, no answer, a fault with nothing said): ours, as before -
1500
+ // and an answer that is no sign-in but no "wrong" either (a form, another
1501
+ // channel) does not blame the password.
1502
+ const said = saidBy(e);
1503
+ if (said)
1504
+ return again('sign_in_refused', 'in', values, said);
1505
+ return again(notThere(e) ? 'busy' : wrong(e) ? 'sign_in_failed' : 'sign_in_unconfirmed');
1506
1506
  }
1507
1507
  finally {
1508
1508
  nameFailures.leave(who, outcome);
1509
1509
  }
1510
- // The whole account, for its page: their sign-in's user_info is short of
1511
- // the email and phone. Theirs only if it is the same member.
1512
- const full = await mall.info(tokens).catch(() => null);
1513
- const m = full && (!member || full.id === member.id) ? full : member;
1514
- if (!m) {
1515
- requests.reopen(r);
1516
- mall.logout(tokens).catch(() => { });
1517
- log(`[account] a sign-in for ${tag(r.key)}: the mall named no member`);
1518
- return again('sign_in_failed');
1519
- }
1520
- const s = signInWith(r.key, m, tokens);
1510
+ // ⚠️ WHAT THE SIGN-IN SAID, AND NOTHING ELSE (0.62.0): there is no /member/info.
1511
+ const s = signInWith(r.key, shownOf(got.session, got.profile, typed), got.session);
1521
1512
  // Every place taken by a live sign-in: none is pushed out (review P3-3).
1522
1513
  if (!s) {
1523
1514
  requests.reopen(r);
1524
1515
  refusals.full++;
1525
- mall.logout(tokens).catch(() => { });
1516
+ void endSession(got.session);
1526
1517
  log('[account] a sign-in refused: every place is taken by a live one');
1527
1518
  return again('busy');
1528
1519
  }
@@ -1649,16 +1640,16 @@ export const makeAccount = (opts) => {
1649
1640
  // name stands with the nickname, and the per-name limit still holds.
1650
1641
  const name = s ? nameOf(s) || undefined : undefined;
1651
1642
  // ⚠️ THE ACCOUNT'S FACTS, FOR A CARD ALONE (0.61.0, robin 11-10: the card's account
1652
- // view is the web page's): the user name, and the email and phone MASKED as the page
1653
- // masks them (store.ts `shownOf`) - never whole, never the real name, never in the
1654
- // words. Only to a session that draws cards: `_meta` may reach the model of one
1655
- // that does not. Whichever conversation the call names, as the hotel memberships'
1656
- // rows are - in claude.ai the card's calls all name the trip.
1643
+ // view is the web page's): the user name, and the email MASKED as the page masks
1644
+ // it (store.ts `shownOf`) - never whole, never in the words. (No phone since
1645
+ // 0.62.0: the sign-in's answer has none.) Only to a session that draws cards:
1646
+ // `_meta` may reach the model of one that does not. Whichever conversation the
1647
+ // call names, as the hotel memberships' rows are - in claude.ai the card's calls
1648
+ // all name the trip.
1657
1649
  const facts = s && cards
1658
1650
  ? {
1659
1651
  ...(s.shown.userName ? { userName: s.shown.userName } : {}),
1660
1652
  ...(s.shown.email ? { email: s.shown.email } : {}),
1661
- ...(s.shown.mobile ? { mobile: s.shown.mobile } : {}),
1662
1653
  }
1663
1654
  : undefined;
1664
1655
  return {
@@ -1689,10 +1680,46 @@ export const makeAccount = (opts) => {
1689
1680
  const s = store.get(key);
1690
1681
  return s ? liveLink(s, group)?.token : undefined;
1691
1682
  },
1683
+ // The backend said the conversation's sign-in at a group is over (a 4012 to a
1684
+ // price; to a booking a 401, or 4012 twice): a linked membership goes - and
1685
+ // where it is the account's own sign-in (its channel, 0.62.0), the account.
1692
1686
  expired: (key, group) => {
1693
1687
  const s = store.get(key);
1694
- if (s?.links?.delete(group))
1695
- log(`[account] ${tag(key)}: a ${group} membership's session is over`);
1688
+ if (!s)
1689
+ return;
1690
+ const code = group.trim().toLowerCase();
1691
+ if (s.links?.delete(code)) {
1692
+ log(`[account] ${tag(key)}: a ${code} membership's session is over`);
1693
+ return;
1694
+ }
1695
+ if (s.platform.provider === code) {
1696
+ log(`[account] ${tag(key)}: the account's own session is over: signed out here`);
1697
+ signOut(key);
1698
+ }
1699
+ },
1700
+ // ⚠️ THE CONVERSATION'S OWN SIGN-IN AT THAT GROUP (see `Account.bookingAuth`).
1701
+ // `account`: their member_user id as the digits they sent (ota-member.ts
1702
+ // `exactId`) - with none given, who `shownOf` says.
1703
+ bookingAuth: (key, group) => {
1704
+ const s = store.get(key);
1705
+ if (!s)
1706
+ return undefined;
1707
+ const code = group.trim().toLowerCase();
1708
+ const account = s.platform.memberUserId || s.shown.id;
1709
+ const l = linking ? liveLink(s, code) : undefined;
1710
+ if (l)
1711
+ return {
1712
+ token: l.token,
1713
+ ...(l.mcpSessionId ? { mcpSessionId: l.mcpSessionId } : {}),
1714
+ account,
1715
+ };
1716
+ if (s.platform.provider !== code)
1717
+ return undefined;
1718
+ return {
1719
+ token: s.platform.access,
1720
+ ...(s.platform.mcpSessionId ? { mcpSessionId: s.platform.mcpSessionId } : {}),
1721
+ account,
1722
+ };
1696
1723
  },
1697
1724
  instructions,
1698
1725
  mount,