@curless/hotel-storefront 0.61.1 → 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 (62) 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 +194 -195
  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 +99 -14
  14. package/dist/account/ota-member.d.ts.map +1 -1
  15. package/dist/account/ota-member.js +167 -48
  16. package/dist/account/ota-member.js.map +1 -1
  17. package/dist/account/pages.d.ts +2 -1
  18. package/dist/account/pages.d.ts.map +1 -1
  19. package/dist/account/pages.js +10 -5
  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.js +2 -2
  25. package/dist/account/said.js.map +1 -1
  26. package/dist/account/store.d.ts +16 -15
  27. package/dist/account/store.d.ts.map +1 -1
  28. package/dist/account/store.js +29 -23
  29. package/dist/account/store.js.map +1 -1
  30. package/dist/otaless/backend.d.ts +19 -3
  31. package/dist/otaless/backend.d.ts.map +1 -1
  32. package/dist/otaless/backend.js +51 -20
  33. package/dist/otaless/backend.js.map +1 -1
  34. package/dist/otaless/booking.d.ts +189 -0
  35. package/dist/otaless/booking.d.ts.map +1 -0
  36. package/dist/otaless/booking.js +1227 -0
  37. package/dist/otaless/booking.js.map +1 -0
  38. package/dist/otaless/client.d.ts +180 -0
  39. package/dist/otaless/client.d.ts.map +1 -1
  40. package/dist/otaless/client.js +166 -15
  41. package/dist/otaless/client.js.map +1 -1
  42. package/dist/otaless/fake.d.ts +73 -0
  43. package/dist/otaless/fake.d.ts.map +1 -1
  44. package/dist/otaless/fake.js +270 -2
  45. package/dist/otaless/fake.js.map +1 -1
  46. package/dist/otaless/make.d.ts +2 -0
  47. package/dist/otaless/make.d.ts.map +1 -1
  48. package/dist/otaless/make.js +32 -0
  49. package/dist/otaless/make.js.map +1 -1
  50. package/dist/server.d.ts +1 -1
  51. package/dist/server.d.ts.map +1 -1
  52. package/dist/server.js +4 -1
  53. package/dist/server.js.map +1 -1
  54. package/package.json +1 -1
  55. package/dist/account/fake-mall.d.ts +0 -61
  56. package/dist/account/fake-mall.d.ts.map +0 -1
  57. package/dist/account/fake-mall.js +0 -239
  58. package/dist/account/fake-mall.js.map +0 -1
  59. package/dist/account/mall.d.ts +0 -94
  60. package/dist/account/mall.d.ts.map +0 -1
  61. package/dist/account/mall.js +0 -255
  62. 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,18 +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
231
  /** What the backend said for its no, cleaned (said.ts) - undefined when it said nothing. */
252
- const saidBy = (e) => e instanceof MallError || e instanceof OtaMemberError ? e.said : undefined;
253
- /** The mall did not answer - not a no. */
254
- const notThere = (e) => e instanceof MallError &&
255
- (e.code === 'timeout' ||
256
- e.code === 'unreachable' ||
257
- (typeof e.code === 'number' && e.code >= 500 && !e.envelope));
232
+ const saidBy = (e) => e instanceof OtaMemberError ? e.said : undefined;
258
233
  export const makeAccount = (opts) => {
259
234
  const now = opts.now ?? (() => Date.now());
260
235
  const env = opts.env ?? process.env;
@@ -262,8 +237,21 @@ export const makeAccount = (opts) => {
262
237
  const baseUrl = env[`${prefix}_API_URL`] || opts.account.baseUrl;
263
238
  const tenant = env[`${prefix}_TENANT_ID`] || opts.account.tenant;
264
239
  if (!baseUrl || !tenant)
265
- throw new Error(`account: no mall address or tenant (account.baseUrl / account.tenant, or ${prefix}_API_URL / ${prefix}_TENANT_ID)`);
266
- 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({
267
255
  baseUrl,
268
256
  tenant,
269
257
  ...(opts.fetch ? { fetch: opts.fetch } : {}),
@@ -272,8 +260,8 @@ export const makeAccount = (opts) => {
272
260
  const log = opts.log ?? ((l) => console.log(l));
273
261
  const names = accountToolNames(opts.prefix);
274
262
  const requests = createSignIns({ now });
275
- // A sign-in forgotten here - left two hours, past its tokens, or pushed out -
276
- // 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).
277
265
  const store = new AccountStore(now, (s) => end(s));
278
266
  const web = new WebSessions(now);
279
267
  // The form's token, from a secret of this process: a restart voids open
@@ -353,12 +341,6 @@ export const makeAccount = (opts) => {
353
341
  return undefined;
354
342
  }
355
343
  };
356
- const ota = makeOtaMembers({
357
- baseUrl,
358
- tenant,
359
- ...(opts.fetch ? { fetch: opts.fetch } : {}),
360
- now,
361
- });
362
344
  // A request table of their own: a link used does not void the account's sign-in links.
363
345
  const linkRequests = createSignIns({ now });
364
346
  const linkCsrf = (r) => createHmac('sha256', secretKey).update(`link:${r.codeHash}`).digest('base64url').slice(0, 32);
@@ -372,17 +354,26 @@ export const makeAccount = (opts) => {
372
354
  s.links?.delete(code);
373
355
  return undefined;
374
356
  };
375
- /** Unlinked: forgotten here, and the group's session ended at the backend (not waited for). */
376
- 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) => {
377
366
  const l = s.links?.get(code);
378
367
  if (!l)
379
- return false;
368
+ return null;
380
369
  s.links?.delete(code);
381
- ota
382
- .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 })
383
374
  .catch((e) => log(`[account] a membership's sign-out did not answer (${codeOf(e)})`));
384
- return true;
385
375
  };
376
+ const unlink = (s, code) => dropLink(s, code) !== null;
386
377
  /** "ASR Member (AS82••36)" → "ASR Member": a label with its hidden number taken out. */
387
378
  const tierOf = (label) => label
388
379
  .replace(/\s*[([(][^)\])]*••[^)\])]*[)\])]/g, '')
@@ -436,22 +427,31 @@ export const makeAccount = (opts) => {
436
427
  };
437
428
  // ── Signing in and out ───────────────────────────────────────────────────
438
429
  /** Signed in now, for this conversation: whatever was there before is ended. */
439
- const signInWith = (key, member, tokens) => {
430
+ const signInWith = (key, shown, platform) => {
440
431
  const was = store.clear(key);
441
432
  if (was)
442
433
  end(was);
443
434
  requests.cancelFor(key);
444
435
  linkRequests.cancelFor(key);
445
- return store.set(key, member, tokens);
436
+ return store.set(key, shown, platform);
446
437
  };
447
- /** 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
+ */
448
451
  const end = (s) => {
449
452
  web.dropFor(s.sid);
450
- for (const code of [...(s.links?.keys() ?? [])])
451
- unlink(s, code);
452
- mall
453
- .logout(s.tokens)
454
- .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));
455
455
  };
456
456
  const signOut = (key) => {
457
457
  const was = store.clear(key);
@@ -464,92 +464,18 @@ export const makeAccount = (opts) => {
464
464
  // The code, and the backend's own words for it where it gave any (0.61.1,
465
465
  // questions #55): `refused (500: Password cannot be empty)`. `said` is
466
466
  // already clean (said.ts): one line, 120 characters, nothing of ours in it.
467
- const codeOf = (e) => e instanceof MallError || e instanceof OtaMemberError
467
+ const codeOf = (e) => e instanceof OtaMemberError
468
468
  ? `${String(e.code).slice(0, 16)}${e.said ? `: ${e.said}` : ''}`
469
469
  : e instanceof Error
470
470
  ? e.name
471
471
  : 'error';
472
472
  /**
473
- * Still theirs? Asked of the mall at most every five minutes: a token
474
- * revoked there - signed out on another device - answers as nobody, and the
475
- * 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).
476
477
  */
477
- // ⚠️ ONE LOOK AT A TIME FOR A CONVERSATION (review P3-5): two at once spent
478
- // the same refresh token, and the mall, rotating it, refused the second -
479
- // read as signed out.
480
- const looking = new Map();
481
- const checked = (key) => {
482
- const s = store.get(key);
483
- if (!s || now() - s.checkedAt < CHECK_EVERY_MS)
484
- return Promise.resolve(s);
485
- const out = looking.get(key);
486
- if (out)
487
- return out;
488
- const p = look(key, s).finally(() => looking.delete(key));
489
- looking.set(key, p);
490
- return p;
491
- };
492
- const look = async (key, s) => {
493
- // ⚠️ ONLY A REFUSED RENEWAL, OR A TOKEN THE MALL SAYS IS NOBODY'S, SIGNS OUT:
494
- // their envelope says 500 for a fault of theirs too (Nexva's audit M-18).
495
- const GONE = new Error('gone');
496
- const renew = async () => {
497
- try {
498
- s.tokens = await mall.refresh(s.tokens);
499
- s.renewFailingSince = undefined;
500
- }
501
- catch (e) {
502
- if (refused(e))
503
- throw GONE;
504
- // ⚠️ A BLIP IS SHORT (0.59.0, review C3). The mall's envelope says 500
505
- // for "no valid buyer" too (apidev, 10-20) - so a 500 here may be a dead
506
- // refresh token, and kept as a blip it would show the guest signed in
507
- // for good. Once the access token has lapsed and no renewal has been
508
- // answered for a quarter of an hour, the sign-in is no use to anyone:
509
- // it goes, as a refused one does.
510
- const since = s.renewFailingSince ?? now();
511
- s.renewFailingSince = since;
512
- if (s.tokens.accessExpires <= now() && now() - since >= RENEW_GIVE_UP_MS)
513
- throw GONE;
514
- throw e;
515
- }
516
- };
517
- const whoIs = () => mall.info(s.tokens).catch((e) => {
518
- if (e instanceof MallError && (e.code === 401 || e.code === 403))
519
- return null;
520
- throw e;
521
- });
522
- try {
523
- if (s.tokens.accessExpires - now() < 60_000)
524
- await renew();
525
- let who = await whoIs();
526
- if (!who || who.id !== s.shown.id) {
527
- await renew();
528
- who = await whoIs();
529
- }
530
- if (!who || who.id !== s.shown.id)
531
- throw GONE;
532
- s.shown = shownOf(who);
533
- s.checkedAt = now();
534
- return s;
535
- }
536
- catch (e) {
537
- // ⚠️ ONLY THE SIGN-IN THIS LOOK WAS FOR (re-review P3-2): signed out and in
538
- // again while the mall kept it waiting, the conversation has a new one,
539
- // which an old token's refusal says nothing about.
540
- const nowIn = store.get(key);
541
- if (nowIn?.sid !== s.sid)
542
- return nowIn;
543
- if (e === GONE) {
544
- log(`[account] ${tag(key)} is not signed in at the mall any more: signed out here`);
545
- signOut(key);
546
- return undefined;
547
- }
548
- // Not now: the sign-in stands, and is asked about again next time.
549
- log(`[account] ${tag(key)}: the mall could not be asked (${codeOf(e)}) - still signed in`);
550
- return nowIn;
551
- }
552
- };
478
+ const checked = (key) => store.get(key);
553
479
  // ── The tools ────────────────────────────────────────────────────────────
554
480
  const NO_PRICE = linking
555
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.`
@@ -568,7 +494,7 @@ export const makeAccount = (opts) => {
568
494
  const shownFor = (s) => (nameOf(s) ? { displayName: nameOf(s) } : {});
569
495
  const whoSaid = (s) => nameOf(s) ? `the ${brand} account of ${nameOf(s)}` : `${aBrand} account`;
570
496
  const signedInAnswer = (s, lead, noCards) => ({
571
- 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(),
572
498
  structured: {
573
499
  view: 'account',
574
500
  brand,
@@ -596,7 +522,7 @@ export const makeAccount = (opts) => {
596
522
  isError: true,
597
523
  };
598
524
  const g = groupSaid(m, noCards);
599
- const s = await checked(key);
525
+ const s = checked(key);
600
526
  if (!s)
601
527
  return {
602
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)}.`,
@@ -712,7 +638,7 @@ export const makeAccount = (opts) => {
712
638
  return linkAnswer(args, call);
713
639
  }
714
640
  if (name === names.view) {
715
- const s = await checked(key);
641
+ const s = checked(key);
716
642
  if (s)
717
643
  return signedInAnswer(s, '', noCards);
718
644
  const waiting = requests.openFor(key);
@@ -760,7 +686,7 @@ export const makeAccount = (opts) => {
760
686
  }
761
687
  if (name !== names.signIn)
762
688
  throw new Error(`not an account tool: ${name}`);
763
- const s = await checked(key);
689
+ const s = checked(key);
764
690
  if (s)
765
691
  return {
766
692
  ...signedInAnswer(s, '', noCards),
@@ -1204,7 +1130,7 @@ export const makeAccount = (opts) => {
1204
1130
  if (!account || !password)
1205
1131
  return reauthPage(c, code, r, lang, 'missing_in');
1206
1132
  // ⚠️ COUNTED AS A SIGN-IN OF THE ACCOUNT IS (总线程 11-06): by the name -
1207
- // 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
1208
1134
  // counts, a success clears the name) - and for everyone.
1209
1135
  const named = `a:${account.toLowerCase()}`;
1210
1136
  if (nameFailures.shut(named, ACCOUNT_LIMITS.perName)) {
@@ -1223,7 +1149,7 @@ export const makeAccount = (opts) => {
1223
1149
  let proved = null;
1224
1150
  let triedOutcome = 'unknown';
1225
1151
  try {
1226
- proved = await mall.login({ account, password });
1152
+ proved = await ota.signIn({ group: signInProvider, identity: account, password, lang });
1227
1153
  triedOutcome = 'ok';
1228
1154
  }
1229
1155
  catch (e) {
@@ -1233,22 +1159,37 @@ export const makeAccount = (opts) => {
1233
1159
  const said = saidBy(e);
1234
1160
  return said
1235
1161
  ? reauthPage(c, code, r, lang, 'sign_in_refused', said)
1236
- : reauthPage(c, code, r, lang, notThere(e) ? 'busy' : 'sign_in_failed');
1162
+ : reauthPage(c, code, r, lang, notThere(e) ? 'busy' : wrong(e) ? 'sign_in_failed' : 'sign_in_unconfirmed');
1237
1163
  }
1238
1164
  finally {
1239
1165
  nameFailures.leave(named, triedOutcome);
1240
1166
  }
1241
1167
  linkRequests.reopen(r);
1242
- // Only to prove who: its tokens are ended at once - the account's own sign-in stands.
1243
- mall.logout(proved.tokens).catch(() => { });
1244
1168
  const still = store.get(r.key);
1245
- 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);
1246
1177
  return notOpen(c, code, 'expired', lang, false);
1247
- // ⚠️ ANOTHER ACCOUNT: refused, and nothing of the link's account said (总线程 11-06 (b)).
1248
- 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);
1249
1182
  log(`[account] a membership link of ${tag(r.key)} opened by another account: refused`);
1250
1183
  return reauthPage(c, code, r, lang, 'reauth_other');
1251
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);
1252
1193
  const id = web.open(r.key, still.sid);
1253
1194
  if (id)
1254
1195
  setCookie(c, id);
@@ -1297,7 +1238,7 @@ export const makeAccount = (opts) => {
1297
1238
  }
1298
1239
  let outcome = 'unknown';
1299
1240
  try {
1300
- const auth = owner.s.tokens.access;
1241
+ const auth = owner.s.platform.access;
1301
1242
  let memberNo;
1302
1243
  if (up) {
1303
1244
  try {
@@ -1312,33 +1253,39 @@ export const makeAccount = (opts) => {
1312
1253
  }
1313
1254
  catch (e) {
1314
1255
  linkRequests.reopen(r);
1315
- outcome = otaNotThere(e) ? 'unknown' : 'failed';
1256
+ outcome = notThere(e) ? 'unknown' : 'failed';
1316
1257
  log(`[account] a membership for ${tag(r.key)} refused (${codeOf(e)})`);
1317
1258
  const said = saidBy(e);
1318
1259
  if (said)
1319
1260
  return again('join_refused', 'up', values, said);
1320
- return again(otaNotThere(e) ? 'link_busy' : 'join_failed');
1261
+ return again(notThere(e) ? 'link_busy' : 'join_failed');
1321
1262
  }
1322
1263
  }
1323
1264
  let link;
1324
1265
  try {
1325
- link = await ota.signIn({
1266
+ const got = await ota.signIn({
1326
1267
  group: m.code,
1327
1268
  identity: (up ? values.email : values.identity) ?? '',
1328
1269
  password,
1329
1270
  auth,
1271
+ lang,
1330
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());
1331
1278
  }
1332
1279
  catch (e) {
1333
1280
  linkRequests.reopen(r);
1334
- outcome = otaNotThere(e) ? 'unknown' : 'failed';
1281
+ outcome = notThere(e) ? 'unknown' : 'failed';
1335
1282
  log(`[account] a membership link for ${tag(r.key)} refused (${codeOf(e)})`);
1336
1283
  const said = saidBy(e);
1337
1284
  if (up)
1338
1285
  return again('joined_not_linked', 'in', { identity: values.email ?? '' }, said);
1339
1286
  if (said)
1340
1287
  return again('link_refused', 'in', values, said);
1341
- return again(otaNotThere(e) ? 'link_busy' : otaWrong(e) ? 'link_failed' : 'link_unconfirmed');
1288
+ return again(notThere(e) ? 'link_busy' : wrong(e) ? 'link_failed' : 'link_unconfirmed');
1342
1289
  }
1343
1290
  outcome = 'ok';
1344
1291
  // Still that sign-in, after the backend kept us waiting?
@@ -1346,17 +1293,30 @@ export const makeAccount = (opts) => {
1346
1293
  if (!now2 || now2.sid !== r.link?.sid) {
1347
1294
  linkRequests.reopen(r);
1348
1295
  ota
1349
- .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
+ })
1350
1301
  .catch(() => { });
1351
1302
  return notOpen(c, code, 'expired', lang, false);
1352
1303
  }
1353
1304
  if (memberNo)
1354
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).
1355
1308
  const was = now2.links?.get(m.code);
1356
- if (was)
1309
+ if (was?.session && was.session === link.session)
1310
+ now2.links?.delete(m.code);
1311
+ else if (was)
1357
1312
  unlink(now2, m.code);
1358
1313
  now2.links ??= new Map();
1359
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;
1360
1320
  linkRequests.done(r);
1361
1321
  log(`[account] ${tag(r.key)} linked a ${m.code} membership${up ? ' it made' : ''}`);
1362
1322
  return send(c, 200, linkedPage(brandPage, {
@@ -1440,7 +1400,7 @@ export const makeAccount = (opts) => {
1440
1400
  error: errorOf(lang, error),
1441
1401
  ...(said ? { said } : {}),
1442
1402
  }));
1443
- // What the form itself can tell, without asking the mall.
1403
+ // What the form itself can tell, without asking the backend.
1444
1404
  const mobile = (values.mobile ?? '').replace(/[\s().-]/g, '');
1445
1405
  if (up) {
1446
1406
  if (!values.userName || !values.email || !password)
@@ -1455,7 +1415,7 @@ export const makeAccount = (opts) => {
1455
1415
  else if (!values.account || !password)
1456
1416
  return again('missing_in');
1457
1417
  // ⚠️ BY THE NAME TOO (Nexva's member_sign_in): one user name's WRONG
1458
- // 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
1459
1419
  // counts (C8, robin 11-09); the check here is a look, the try is reserved
1460
1420
  // below once nothing else can turn this post away.
1461
1421
  const who = `${up ? 'r' : 'a'}:${(up ? values.userName : values.account)?.toLowerCase()}`;
@@ -1479,18 +1439,23 @@ export const makeAccount = (opts) => {
1479
1439
  return again('too_many');
1480
1440
  }
1481
1441
  let outcome = 'unknown';
1482
- let tokens;
1483
- let member;
1442
+ let got;
1443
+ let typed = values.account ?? '';
1484
1444
  try {
1485
1445
  if (up) {
1446
+ let channels;
1486
1447
  try {
1487
- 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({
1488
1452
  userName: values.userName ?? '',
1489
1453
  email: values.email ?? '',
1490
1454
  password,
1491
- ...(mobile ? { mobile } : {}),
1492
- ...(values.nickname ? { nickname: values.nickname } : {}),
1493
- });
1455
+ ...(values.nickname ? { name: values.nickname } : {}),
1456
+ ...(mobile ? { phone: mobile } : {}),
1457
+ lang,
1458
+ }));
1494
1459
  }
1495
1460
  catch (e) {
1496
1461
  requests.reopen(r);
@@ -1502,17 +1467,22 @@ export const makeAccount = (opts) => {
1502
1467
  return again(notThere(e) ? 'busy' : 'register_failed');
1503
1468
  }
1504
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 ?? '';
1505
1475
  try {
1506
- ({ tokens, member } = await mall.login({ account: values.userName ?? '', password }));
1476
+ got = await ota.signIn({ group: signInProvider, identity: typed, password, lang });
1507
1477
  }
1508
1478
  catch (e) {
1509
1479
  requests.reopen(r);
1510
1480
  log(`[account] an account was made for ${tag(r.key)}; signing in refused (${codeOf(e)})`);
1511
- return again('registered_not_signed_in', 'in', { account: values.userName ?? '' }, saidBy(e));
1481
+ return again('registered_not_signed_in', 'in', { account: typed }, saidBy(e));
1512
1482
  }
1513
1483
  }
1514
1484
  else {
1515
- ({ tokens, member } = await mall.login({ account: values.account ?? '', password }));
1485
+ got = await ota.signIn({ group: signInProvider, identity: typed, password, lang });
1516
1486
  outcome = 'ok';
1517
1487
  }
1518
1488
  }
@@ -1520,37 +1490,30 @@ export const makeAccount = (opts) => {
1520
1490
  requests.reopen(r);
1521
1491
  outcome = notThere(e) ? 'unknown' : 'failed';
1522
1492
  log(`[account] a sign-in for ${tag(r.key)} refused (${codeOf(e)})`);
1523
- // ⚠️ THE MALL'S OWN WORDS, UNDER A LINE OF OURS THAT GUESSES NOTHING
1493
+ // ⚠️ THE BACKEND'S OWN WORDS, UNDER A LINE OF OURS THAT GUESSES NOTHING
1524
1494
  // (0.61.1, robin: 供应方原文照原样显示; questions #55 - every no is their
1525
1495
  // 500, and our guess 「用户名或密码不对」 was as likely wrong). Nexva's
1526
1496
  // review P3 kept them off the page because they can tell a taken user name
1527
1497
  // from a wrong password; what still bounds that probe is the per-name
1528
1498
  // count above and the sign-ins-per-minute for everyone. No words from
1529
- // them (a timeout, no answer, a fault with nothing said): ours, as before.
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.
1530
1502
  const said = saidBy(e);
1531
1503
  if (said)
1532
1504
  return again('sign_in_refused', 'in', values, said);
1533
- return again(notThere(e) ? 'busy' : 'sign_in_failed');
1505
+ return again(notThere(e) ? 'busy' : wrong(e) ? 'sign_in_failed' : 'sign_in_unconfirmed');
1534
1506
  }
1535
1507
  finally {
1536
1508
  nameFailures.leave(who, outcome);
1537
1509
  }
1538
- // The whole account, for its page: their sign-in's user_info is short of
1539
- // the email and phone. Theirs only if it is the same member.
1540
- const full = await mall.info(tokens).catch(() => null);
1541
- const m = full && (!member || full.id === member.id) ? full : member;
1542
- if (!m) {
1543
- requests.reopen(r);
1544
- mall.logout(tokens).catch(() => { });
1545
- log(`[account] a sign-in for ${tag(r.key)}: the mall named no member`);
1546
- return again('sign_in_failed');
1547
- }
1548
- 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);
1549
1512
  // Every place taken by a live sign-in: none is pushed out (review P3-3).
1550
1513
  if (!s) {
1551
1514
  requests.reopen(r);
1552
1515
  refusals.full++;
1553
- mall.logout(tokens).catch(() => { });
1516
+ void endSession(got.session);
1554
1517
  log('[account] a sign-in refused: every place is taken by a live one');
1555
1518
  return again('busy');
1556
1519
  }
@@ -1677,16 +1640,16 @@ export const makeAccount = (opts) => {
1677
1640
  // name stands with the nickname, and the per-name limit still holds.
1678
1641
  const name = s ? nameOf(s) || undefined : undefined;
1679
1642
  // ⚠️ THE ACCOUNT'S FACTS, FOR A CARD ALONE (0.61.0, robin 11-10: the card's account
1680
- // view is the web page's): the user name, and the email and phone MASKED as the page
1681
- // masks them (store.ts `shownOf`) - never whole, never the real name, never in the
1682
- // words. Only to a session that draws cards: `_meta` may reach the model of one
1683
- // that does not. Whichever conversation the call names, as the hotel memberships'
1684
- // 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.
1685
1649
  const facts = s && cards
1686
1650
  ? {
1687
1651
  ...(s.shown.userName ? { userName: s.shown.userName } : {}),
1688
1652
  ...(s.shown.email ? { email: s.shown.email } : {}),
1689
- ...(s.shown.mobile ? { mobile: s.shown.mobile } : {}),
1690
1653
  }
1691
1654
  : undefined;
1692
1655
  return {
@@ -1717,10 +1680,46 @@ export const makeAccount = (opts) => {
1717
1680
  const s = store.get(key);
1718
1681
  return s ? liveLink(s, group)?.token : undefined;
1719
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.
1720
1686
  expired: (key, group) => {
1721
1687
  const s = store.get(key);
1722
- if (s?.links?.delete(group))
1723
- 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
+ };
1724
1723
  },
1725
1724
  instructions,
1726
1725
  mount,