@curless/hotel-storefront 0.71.4 → 0.72.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.
@@ -36,10 +36,15 @@ import { AccountStore, WEB_IDLE_MS, WebSessions, nameShown, profileOf, profileSh
36
36
  // an answer or the card - only back to the backend, and (`bookingAuth`) to this
37
37
  // process's own booking calls for the same conversation.
38
38
  //
39
- // ⚠️ WHICH CHANNEL THE ACCOUNT SIGNS IN ON IS NOT SETTLED (questions #50): their
40
- // `/ota/sign-in` wants a providerCode, and says nothing of the platform's own.
41
- // Until they answer, `account.signInProvider` - `ascott` by default, the one their
42
- // own Postman sign-in worked on - and `<envPrefix>_SIGN_IN_PROVIDER` over it.
39
+ // ⚠️ THE ACCOUNT SIGNS IN WITH NO providerCode (0.72.0, robin 11-16 through 总线程:
40
+ // 「不带 providerCode 是平台登录,带 providerCode 是关联酒店集团会员的登录」) - the
41
+ // Otaless account at no group. The backend before the 11-16 document wants a
42
+ // providerCode on every sign-in: where it refuses one with none, the same sign-in is
43
+ // asked again on `ascott` (FALLBACK_SIGN_IN_PROVIDER, the one their own Postman sign-in
44
+ // worked on), and the log says which way it went. A deployment that sets
45
+ // `account.signInProvider` (or `<envPrefix>_SIGN_IN_PROVIDER`) signs in on that channel
46
+ // alone, as before 0.72.0. Signed in at no group, Ascott is linked like any other group
47
+ // before it is booked (`bookingAuth`).
43
48
  //
44
49
  // ⚠️ FORWARDED PHISHING (Nexva's review P1-1): a link passed on to someone else
45
50
  // signs THEIR account into the conversation it came from. Against it: the short
@@ -61,6 +66,11 @@ import { AccountStore, WEB_IDLE_MS, WebSessions, nameShown, profileOf, profileSh
61
66
  // ⚠️ NO MEMBER PRICE YET (robin, 2026-11-06): what signing in buys is waiting
62
67
  // on the backend (docs/otaless-backend-questions.md, 「会员」). Nothing here says
63
68
  // it changes a price, and the words say it does not.
69
+ /**
70
+ * The channel a sign-in with no providerCode is asked again on, where the backend
71
+ * refuses it (0.72.0 - the backend before the 11-16 document wants one on every sign-in).
72
+ */
73
+ export const FALLBACK_SIGN_IN_PROVIDER = 'ascott';
64
74
  /** An email as the pages check one: something@something.something, no spaces. */
65
75
  const EMAIL_SHAPE = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
66
76
  /**
@@ -311,13 +321,11 @@ export const makeAccount = (opts) => {
311
321
  // config still naming it is a mistake to stop on, not to guess past.
312
322
  if (opts.account.source !== 'ota')
313
323
  throw new Error(`account: source must be "ota" (the backend's /api/v1/ota/*), not ${JSON.stringify(opts.account.source)}`);
314
- // The channel the account signs in on - see the top of this file (questions #50).
315
- const signInProvider = (env[`${prefix}_SIGN_IN_PROVIDER`] ||
316
- opts.account.signInProvider ||
317
- 'ascott')
324
+ // The channel the account signs in on, where one is set - see the top of this file.
325
+ const signInProvider = (env[`${prefix}_SIGN_IN_PROVIDER`] || opts.account.signInProvider || '')
318
326
  .trim()
319
327
  .toLowerCase();
320
- if (!/^[a-z0-9_-]{1,32}$/.test(signInProvider))
328
+ if (signInProvider && !/^[a-z0-9_-]{1,32}$/.test(signInProvider))
321
329
  throw new Error('account: signInProvider is not a channel code');
322
330
  // What the account signs in with (0.66.0, 总线程 11-11) - see `signInIdentity`.
323
331
  if ((opts.account.signInIdentity ?? 'email') !== 'email')
@@ -437,7 +445,9 @@ export const makeAccount = (opts) => {
437
445
  };
438
446
  /**
439
447
  * Unlinked: forgotten here, and the group's session ended at the backend - the
440
- * promise of that, or null where there was no link.
448
+ * promise of that, or null where there was no link. ⚠️ WITH ITS providerCode, AND THE
449
+ * CONVERSATION'S LATEST TOKEN (0.72.0, 总线程 11-16): one channel ended, the token kept
450
+ * good for the rest (the 11-16 document) - a link has no token of its own any more.
441
451
  *
442
452
  * ⚠️ NOT THE ACCOUNT'S OWN CHANNEL SESSION: a group linked on the channel the
443
453
  * account signed in on may come back with the account's own `mcpToken` (one
@@ -451,7 +461,11 @@ export const makeAccount = (opts) => {
451
461
  if (l.session && l.session === s.platform.mcpToken)
452
462
  return Promise.resolve();
453
463
  return ota
454
- .signOut({ group: code, ...(l.session ? { session: l.session } : {}), auth: l.token })
464
+ .signOut({
465
+ group: code,
466
+ ...(l.session ? { session: l.session } : {}),
467
+ auth: s.platform.access,
468
+ })
455
469
  .catch((e) => log(`[account] a membership's sign-out did not answer (${codeOf(e)})`));
456
470
  };
457
471
  const unlink = (s, code) => dropLink(s, code) !== null;
@@ -517,23 +531,58 @@ export const makeAccount = (opts) => {
517
531
  termsRequests.cancelFor(key);
518
532
  return store.set(key, shown, platform, profile);
519
533
  };
520
- /** A channel session of the account's own, ended at the backend (not waited for). */
521
- const endSession = (p) => ota
522
- .signOut({
523
- group: p.provider,
524
- ...(p.mcpToken ? { session: p.mcpToken } : {}),
525
- auth: p.access,
526
- })
527
- .catch((e) => log(`[account] the backend's sign-out did not answer (${codeOf(e)})`));
528
534
  /**
529
- * A sign-in that is over: its pages closed, its memberships unlinked, its session
530
- * ended at the backend (not waited for) - ⚠️ THE MEMBERSHIPS FIRST: they share the
531
- * account's local session (their document), so it is ended only after theirs.
535
+ * Signed out at the backend, EVERY CHANNEL OF THE TOKEN AT ONCE (0.72.0, 总线程 11-16):
536
+ * `/ota/signOut` with no providerCode - the 11-16 document's way. With a providerCode
537
+ * it ends that channel alone and the token stays good until it runs out: the
538
+ * `ascott` this used to send left the guest's other groups signed in.
539
+ *
540
+ * ⚠️ THE BACKEND BEFORE 11-16 refuses a sign-out with no providerCode (when it goes
541
+ * live is not known): where it answers no, one channel at a time - `each` first (the
542
+ * memberships: they share the account's local session, their document, so it is
543
+ * ended only after theirs), then `own`, the account's own channel. A backend that
544
+ * did not answer at all is not asked again. Never throws; nothing waits for it.
545
+ */
546
+ const signOutAll = async (token, own, each = []) => {
547
+ try {
548
+ await ota.signOut({ auth: token });
549
+ return;
550
+ }
551
+ catch (e) {
552
+ if (e instanceof OtaMemberError && (e.code === 'timeout' || e.code === 'unreachable')) {
553
+ log(`[account] the backend's sign-out did not answer (${codeOf(e)})`);
554
+ return;
555
+ }
556
+ log(`[account] signing out every channel at once was refused (${codeOf(e)}): one at a time`);
557
+ }
558
+ await Promise.allSettled(each.map((l) => ota
559
+ .signOut({ group: l.group, ...(l.session ? { session: l.session } : {}), auth: token })
560
+ .catch((e) => log(`[account] a membership's sign-out did not answer (${codeOf(e)})`))));
561
+ // The platform's own sign-in (no channel) has no channel session of its own to end.
562
+ if (!own.provider)
563
+ return;
564
+ await ota
565
+ .signOut({
566
+ group: own.provider,
567
+ ...(own.mcpToken ? { session: own.mcpToken } : {}),
568
+ auth: token,
569
+ })
570
+ .catch((e) => log(`[account] the backend's sign-out did not answer (${codeOf(e)})`));
571
+ };
572
+ /** A session of the account's own - with no memberships of ours on it - ended at the backend (not waited for). */
573
+ const endSession = (p) => signOutAll(p.access, p);
574
+ /**
575
+ * A sign-in that is over: its pages closed, its memberships forgotten, every channel
576
+ * of its token ended at the backend (not waited for, `signOutAll`).
532
577
  */
533
578
  const end = (s) => {
534
579
  web.dropFor(s.sid);
535
- const links = [...(s.links?.keys() ?? [])].map((code) => dropLink(s, code));
536
- void Promise.allSettled(links).then(() => endSession(s.platform));
580
+ // A membership that came back with the account's own channel session is ended with it.
581
+ const each = [...(s.links?.values() ?? [])]
582
+ .filter((l) => !(l.session && l.session === s.platform.mcpToken))
583
+ .map((l) => ({ group: l.group, ...(l.session ? { session: l.session } : {}) }));
584
+ s.links?.clear();
585
+ void signOutAll(s.platform.access, s.platform, each);
537
586
  };
538
587
  const signOut = (key) => {
539
588
  const was = store.clear(key);
@@ -564,6 +613,37 @@ export const makeAccount = (opts) => {
564
613
  if (e instanceof OtaMemberError && e.shape)
565
614
  log(`[account] the answer to that sign-in (${String(e.code).slice(0, 16)}): ${e.shape}`);
566
615
  };
616
+ /**
617
+ * THE ACCOUNT'S OWN SIGN-IN (0.72.0) - on our sign-in page, after an account is made,
618
+ * and again on a membership's or the terms' page: with no providerCode (the 11-16
619
+ * document's platform sign-in); where the backend answers no to that - the backend
620
+ * before it wants a providerCode - the same sign-in once more on
621
+ * FALLBACK_SIGN_IN_PROVIDER, and its answer is the one that counts. A backend that did
622
+ * not answer is not asked again. With `account.signInProvider` set: that channel alone.
623
+ * The log says which way it went (总线程 11-16: robin signs in, 总线程 reads the log).
624
+ */
625
+ const platformSignIn = async (who, identity, password, lang) => {
626
+ if (signInProvider)
627
+ return ota.signIn({ group: signInProvider, identity, password, lang });
628
+ try {
629
+ const got = await ota.signIn({ identity, password, lang });
630
+ log(`[account] ${who}: the account signed in with no providerCode (the platform's own)`);
631
+ return got;
632
+ }
633
+ catch (e) {
634
+ if (notThere(e))
635
+ throw e;
636
+ logRefused(`[account] ${who}: a sign-in with no providerCode was refused (${codeOf(e)}) - again on ${FALLBACK_SIGN_IN_PROVIDER}`, e);
637
+ }
638
+ const got = await ota.signIn({
639
+ group: FALLBACK_SIGN_IN_PROVIDER,
640
+ identity,
641
+ password,
642
+ lang,
643
+ });
644
+ log(`[account] ${who}: the account signed in on ${FALLBACK_SIGN_IN_PROVIDER} (the fallback)`);
645
+ return got;
646
+ };
567
647
  /**
568
648
  * The conversation's sign-in, while its session stands. ⚠️ NOTHING TO ASK THE
569
649
  * BACKEND ANY MORE (0.62.0): their `/ota/*` has no /member/info and no refresh
@@ -1312,7 +1392,7 @@ export const makeAccount = (opts) => {
1312
1392
  let proved = null;
1313
1393
  let triedOutcome = 'unknown';
1314
1394
  try {
1315
- proved = await ota.signIn({ group: signInProvider, identity: account, password, lang });
1395
+ proved = await platformSignIn(tag(r.key), account, password, lang);
1316
1396
  triedOutcome = 'ok';
1317
1397
  }
1318
1398
  catch (e) {
@@ -1347,12 +1427,12 @@ export const makeAccount = (opts) => {
1347
1427
  }
1348
1428
  // ⚠️ THE SAME ACCOUNT: ITS NEWER SESSION IS KEPT, NOT ENDED (0.62.0). Their
1349
1429
  // document keeps one local session for a member's sign-ins - ending this
1350
- // one could end the account's own. The older is ended only where it shares
1351
- // neither token with the newer.
1352
- const older = still.platform;
1430
+ // one could end the account's own. ⚠️ AND THE OLDER IS NOT ENDED EITHER (0.72.0):
1431
+ // the newer token is the conversation's from now on (its memberships ride on it),
1432
+ // the 11-16 backend voids the older itself, and ending it now means every channel
1433
+ // at once (`signOutAll`) - which, if the backend counts channels by the member,
1434
+ // would end the newer's too (questions #77, #83).
1353
1435
  still.platform = proved.session;
1354
- if (!same(older, proved.session))
1355
- void endSession(older);
1356
1436
  const id = web.open(r.key, still.sid);
1357
1437
  if (id)
1358
1438
  setCookie(c, id);
@@ -1436,8 +1516,9 @@ export const makeAccount = (opts) => {
1436
1516
  }
1437
1517
  }
1438
1518
  let link;
1519
+ let got;
1439
1520
  try {
1440
- const got = await ota.signIn({
1521
+ got = await ota.signIn({
1441
1522
  group: m.code,
1442
1523
  identity: (up ? values.email : values.identity) ?? '',
1443
1524
  password,
@@ -1471,15 +1552,30 @@ export const makeAccount = (opts) => {
1471
1552
  .signOut({
1472
1553
  group: m.code,
1473
1554
  ...(link.session ? { session: link.session } : {}),
1474
- auth: link.token,
1555
+ auth: got.session.access,
1475
1556
  })
1476
1557
  .catch(() => { });
1477
1558
  return notOpen(c, code, 'expired', lang, false);
1478
1559
  }
1479
1560
  if (memberNo)
1480
1561
  link.numberMasked = maskNumber(memberNo);
1481
- // A link there already is replaced - its session ended only where it is not
1482
- // the one just signed in (one session, their document).
1562
+ // ⚠️ THE GROUP'S TOKEN IS THE CONVERSATION'S TOKEN FROM NOW ON (0.72.0, 总线程
1563
+ // 11-16 - the 11-16 document: 「以最后登录的 access token 为准,会覆盖前面的」):
1564
+ // every call after - the account's own channel, every linked group's prices and
1565
+ // bookings, an unlink, the sign-out - carries this one. An older token may be
1566
+ // void: kept per group, linking Atour sent Ascott's booking an old token (401,
1567
+ // and the whole account signed out), and linking a second group lost the first.
1568
+ // Where the backend handed back the same token (the document before: one local
1569
+ // session, renewed to the longest), the account lasts as long as the longer;
1570
+ // a new token lasts as long as its own sign-in said.
1571
+ const renewed = got.session.access === now2.platform.access;
1572
+ now2.platform.access = got.session.access;
1573
+ now2.platform.expires = renewed
1574
+ ? Math.max(now2.platform.expires, got.session.expires)
1575
+ : got.session.expires;
1576
+ // A link there already is replaced - its session ended (with the token just
1577
+ // taken, as every unlink) only where it is not the one just signed in (one
1578
+ // session, their document).
1483
1579
  const was = now2.links?.get(m.code);
1484
1580
  if (was?.session && was.session === link.session)
1485
1581
  now2.links?.delete(m.code);
@@ -1487,11 +1583,6 @@ export const makeAccount = (opts) => {
1487
1583
  unlink(now2, m.code);
1488
1584
  now2.links ??= new Map();
1489
1585
  now2.links.set(m.code, link);
1490
- // ⚠️ ONE LOCAL SESSION, AT ITS LONGEST (their document: several channels'
1491
- // sign-ins share the account's session, renewed to the longest): where the
1492
- // group came back with the account's own token, the account lasts as long.
1493
- if (link.token === now2.platform.access && link.expires > now2.platform.expires)
1494
- now2.platform.expires = link.expires;
1495
1586
  linkRequests.done(r);
1496
1587
  log(`[account] ${tag(r.key)} linked a ${m.code} membership${up ? ' it made' : ''}`);
1497
1588
  usage({
@@ -1770,7 +1861,7 @@ export const makeAccount = (opts) => {
1770
1861
  let proved = null;
1771
1862
  let outcome = 'unknown';
1772
1863
  try {
1773
- proved = await ota.signIn({ group: signInProvider, identity: account, password, lang });
1864
+ proved = await platformSignIn(tag(r.key), account, password, lang);
1774
1865
  outcome = 'ok';
1775
1866
  }
1776
1867
  catch (e) {
@@ -1800,10 +1891,8 @@ export const makeAccount = (opts) => {
1800
1891
  log(`[account] a terms link of ${tag(r.key)} opened by another account: refused`);
1801
1892
  return termsReauth(c, code, r, lang, 'reauth_other');
1802
1893
  }
1803
- const older = still.platform;
1894
+ // The newer kept, the older left to the backend - as the membership page (0.72.0).
1804
1895
  still.platform = proved.session;
1805
- if (!sameTok(older, proved.session))
1806
- void endSession(older);
1807
1896
  const id = web.open(r.key, still.sid);
1808
1897
  if (id)
1809
1898
  setCookie(c, id);
@@ -2081,7 +2170,7 @@ export const makeAccount = (opts) => {
2081
2170
  // sign-in asks for `identity_field: email`, questions #48).
2082
2171
  typed = values.email ?? '';
2083
2172
  try {
2084
- got = await ota.signIn({ group: signInProvider, identity: typed, password, lang });
2173
+ got = await platformSignIn(tag(r.key), typed, password, lang);
2085
2174
  }
2086
2175
  catch (e) {
2087
2176
  requests.reopen(r);
@@ -2092,7 +2181,7 @@ export const makeAccount = (opts) => {
2092
2181
  }
2093
2182
  }
2094
2183
  else {
2095
- got = await ota.signIn({ group: signInProvider, identity: typed, password, lang });
2184
+ got = await platformSignIn(tag(r.key), typed, password, lang);
2096
2185
  outcome = 'ok';
2097
2186
  }
2098
2187
  }
@@ -2315,11 +2404,13 @@ export const makeAccount = (opts) => {
2315
2404
  if (signOut(key))
2316
2405
  log(`[account] ${tag(key)} signed out: taken over from another network`);
2317
2406
  },
2407
+ // A linked group's prices are asked for with the conversation's one token (0.72.0):
2408
+ // the latest sign-in's, whichever group it was at - a link keeps none of its own.
2318
2409
  tokenFor: (key, group) => {
2319
2410
  if (!linking)
2320
2411
  return undefined;
2321
2412
  const s = store.get(key);
2322
- return s ? liveLink(s, group)?.token : undefined;
2413
+ return s && liveLink(s, group) ? s.platform.access : undefined;
2323
2414
  },
2324
2415
  // The backend said the conversation's sign-in at a group is over (a 4012 to a
2325
2416
  // price; to a booking a 401, or 4012 twice): a linked membership goes - and
@@ -2340,7 +2431,9 @@ export const makeAccount = (opts) => {
2340
2431
  },
2341
2432
  // ⚠️ THE CONVERSATION'S OWN SIGN-IN AT THAT GROUP (see `Account.bookingAuth`).
2342
2433
  // `account`: their member_user id as the digits they sent (ota-member.ts
2343
- // `exactId`) - with none given, who `shownOf` says.
2434
+ // `exactId`) - with none given, who `shownOf` says. ⚠️ THE TOKEN IS THE
2435
+ // CONVERSATION'S ONE, the latest sign-in's (0.72.0); the `Mcp-Session-Id` is still
2436
+ // the group's own sign-in's (whether a newer sign-in replaces it too is questions #77).
2344
2437
  bookingAuth: (key, group) => {
2345
2438
  const s = store.get(key);
2346
2439
  if (!s)
@@ -2350,12 +2443,19 @@ export const makeAccount = (opts) => {
2350
2443
  const l = linking ? liveLink(s, code) : undefined;
2351
2444
  if (l)
2352
2445
  return {
2353
- token: l.token,
2446
+ token: s.platform.access,
2354
2447
  ...(l.mcpSessionId ? { mcpSessionId: l.mcpSessionId } : {}),
2355
2448
  account,
2356
2449
  };
2357
- if (s.platform.provider !== code)
2450
+ if (s.platform.provider !== code) {
2451
+ // ⚠️ SIGNED IN AT NO GROUP (0.72.0, 总线程 11-16): the platform's own sign-in books
2452
+ // nowhere by itself - Ascott is linked like any group first, and the answer gives
2453
+ // the link. Whether its token alone could book there is questions #78 - logged,
2454
+ // so a refusal here can be read against the backend's answer.
2455
+ if (!s.platform.provider && code === FALLBACK_SIGN_IN_PROVIDER)
2456
+ log(`[account] ${tag(key)}: a booking at ${code} asks for a link - the account signed in with no providerCode (questions #78)`);
2358
2457
  return undefined;
2458
+ }
2359
2459
  return {
2360
2460
  token: s.platform.access,
2361
2461
  ...(s.platform.mcpSessionId ? { mcpSessionId: s.platform.mcpSessionId } : {}),