@curless/hotel-storefront 0.73.1 → 0.74.1
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.
- package/dist/account/index.d.ts +16 -6
- package/dist/account/index.d.ts.map +1 -1
- package/dist/account/index.js +184 -33
- package/dist/account/index.js.map +1 -1
- package/dist/account/pages.d.ts +5 -1
- package/dist/account/pages.d.ts.map +1 -1
- package/dist/account/pages.js +11 -7
- package/dist/account/pages.js.map +1 -1
- package/dist/account/store.d.ts +4 -2
- package/dist/account/store.d.ts.map +1 -1
- package/dist/account/store.js.map +1 -1
- package/dist/card.generated.d.ts +1 -1
- package/dist/card.generated.js +2 -2
- package/dist/card.generated.js.map +1 -1
- package/dist/otaless/booking.d.ts +20 -1
- package/dist/otaless/booking.d.ts.map +1 -1
- package/dist/otaless/booking.js +273 -124
- package/dist/otaless/booking.js.map +1 -1
- package/dist/otaless/client.d.ts +53 -24
- package/dist/otaless/client.d.ts.map +1 -1
- package/dist/otaless/client.js +10 -7
- package/dist/otaless/client.js.map +1 -1
- package/dist/otaless/fake.d.ts +32 -1
- package/dist/otaless/fake.d.ts.map +1 -1
- package/dist/otaless/fake.js +84 -22
- package/dist/otaless/fake.js.map +1 -1
- package/dist/server.d.ts +2 -2
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +7 -2
- package/dist/server.js.map +1 -1
- package/dist/tools.d.ts.map +1 -1
- package/dist/tools.js +13 -7
- package/dist/tools.js.map +1 -1
- package/package.json +1 -1
package/dist/account/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Context, Hono } from 'hono';
|
|
2
2
|
import type { TermsToAgree } from '../otaless/booking.js';
|
|
3
|
+
import type { StateFile } from '../state.js';
|
|
3
4
|
import { type Lang } from './requests.js';
|
|
4
5
|
/**
|
|
5
6
|
* The channel a sign-in with no providerCode is asked again on, where the backend
|
|
@@ -76,7 +77,6 @@ export declare const SIGN_IN_META_KEY = "curless/account-sign-in";
|
|
|
76
77
|
/** …and beside a membership link's answer (0.58.0): the link and its group - no code (0.61.0). */
|
|
77
78
|
export declare const LINK_META_KEY = "curless/account-link";
|
|
78
79
|
export declare const COOKIE = "__Host-hotel_account";
|
|
79
|
-
/** How many of what, and over how long - each refusal said as "too many requests". */
|
|
80
80
|
export declare const ACCOUNT_LIMITS: {
|
|
81
81
|
/** Sign-in links one conversation may ask for in ten minutes. */
|
|
82
82
|
readonly linksPerConversation: 10;
|
|
@@ -156,15 +156,20 @@ export type Account = {
|
|
|
156
156
|
memberOf: (key: string) => string | undefined;
|
|
157
157
|
/** The conversation's sign-in ended here and at the backend, saying nothing (0.67.1: taken over from another network). */
|
|
158
158
|
forget: (key: string) => void;
|
|
159
|
-
/** The backend said the group's session is over (its 4012): the link
|
|
159
|
+
/** The backend said the group's session is over (its 4012): the link is to be made again (remembered, flagged). */
|
|
160
160
|
expired: (key: string, group: string) => void;
|
|
161
|
+
/**
|
|
162
|
+
* The backend refused the account's own token (401, 0.74.1): the conversation is signed out
|
|
163
|
+
* HERE - nothing sent to the backend with a token it refuses; remembered links stay.
|
|
164
|
+
*/
|
|
165
|
+
ended: (key: string) => void;
|
|
161
166
|
/**
|
|
162
167
|
* For a booking at a group (0.62.0, src/otaless/booking.ts `BookingAuth` /
|
|
163
168
|
* `GroupSignIn`, robin 11-10: 「下单用 /ota/sign-in 的 token」): this
|
|
164
|
-
* conversation's
|
|
165
|
-
*
|
|
166
|
-
*
|
|
167
|
-
*
|
|
169
|
+
* conversation's own sign-in to the account - for EVERY group (0.74.0, robin 11-17:
|
|
170
|
+
* no group is linked before it is booked; the backend says when one must be), with the
|
|
171
|
+
* `Mcp-Session-Id` of a live link of that group, or of the account's own sign-in where
|
|
172
|
+
* it was on that group's channel.
|
|
168
173
|
* `token` its `accessToken`, `mcpSessionId` its `mcpSessionId` (absent: booking.ts
|
|
169
174
|
* makes one, item 16), `account` the account's member_user id - an order's owner,
|
|
170
175
|
* which booking.ts keeps hashed. Undefined: not signed in at that group.
|
|
@@ -253,6 +258,11 @@ export type AccountOptions = {
|
|
|
253
258
|
* (`/suppliers/<code>/logo.png?v=…`, server.ts), or none: its initials (0.61.0).
|
|
254
259
|
*/
|
|
255
260
|
groupLogo?: (code: string) => string | undefined;
|
|
261
|
+
/**
|
|
262
|
+
* Where the links to hotel groups' memberships are remembered, per Otaless account
|
|
263
|
+
* (`account-links.json` of the state directory, 0.74.0). None: in memory, this process only.
|
|
264
|
+
*/
|
|
265
|
+
linksFile?: StateFile;
|
|
256
266
|
operator?: string;
|
|
257
267
|
/** The one-time terms page (0.63.0): absent, `termsLink` gives nothing and `/account?terms=` is not a page. */
|
|
258
268
|
terms?: AccountTerms;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/account/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAI1C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/account/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAI1C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAC1D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAoC7C,OAAO,EAEL,KAAK,IAAI,EAMV,MAAM,eAAe,CAAC;AA4EvB;;;GAGG;AACH,eAAO,MAAM,yBAAyB,WAAW,CAAC;AAgBlD,eAAO,MAAM,mBAAmB,GAAI,GAAG,OAAO,KAAG,OAI3B,CAAC;AAKvB,MAAM,MAAM,aAAa,GAAG;IAC1B,iFAAiF;IACjF,MAAM,EAAE,KAAK,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,C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B,GAAG,EAAE,MAAM,MAAM,EACjB,OAAO,SAAS;IAGnC,OAAO,CAAC,MAAM;IAKd,8FAA8F;IAC9F,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO;IAIvC,uEAAuE;IACvE,KAAK,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO;IAMxC,wGAAwG;IACxG,KAAK,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,QAAQ,GAAG,IAAI,GAAG,SAAS,GAAG,IAAI;CAyB/D;AAkCD,eAAO,MAAM,WAAW,GAAI,MAAM,cAAc,KAAG,OAqoFlD,CAAC"}
|
package/dist/account/index.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { createHmac, randomBytes } from 'node:crypto';
|
|
1
|
+
import { createHash, createHmac, randomBytes } from 'node:crypto';
|
|
2
2
|
import { bodyLimit } from 'hono/body-limit';
|
|
3
3
|
import { WindowCounter } from '../limits.js';
|
|
4
4
|
import { formatMoney } from '../money.js';
|
|
5
5
|
import { withTrip } from '../trip-ids.js';
|
|
6
6
|
import { AccountInfos } from './info-cache.js';
|
|
7
|
+
import { maskEmail } from './mask.js';
|
|
7
8
|
import { LIMITS, OtaMemberError, linkOf, makeOtaMembers, maskLabel, maskNumber, } from './ota-member.js';
|
|
8
9
|
import { PAGE_HEADERS, accountPage, linkGroupPage, linkReauthPage, linkedPage, loginPage, say, signedInPage, statePage, termsDonePage, termsPage, termsStatePage, } from './pages.js';
|
|
9
10
|
import { CODE, createSignIns, hashOf, same, } from './requests.js';
|
|
@@ -45,8 +46,8 @@ import { AccountStore, WEB_IDLE_MS, WebSessions, nameShown, nicknameOf, profileO
|
|
|
45
46
|
// asked again on `ascott` (FALLBACK_SIGN_IN_PROVIDER, the one their own Postman sign-in
|
|
46
47
|
// worked on), and the log says which way it went; any other no is the answer. A deployment that sets
|
|
47
48
|
// `account.signInProvider` (or `<envPrefix>_SIGN_IN_PROVIDER`) signs in on that channel
|
|
48
|
-
// alone, as before 0.72.0.
|
|
49
|
-
//
|
|
49
|
+
// alone, as before 0.72.0. Every group is booked with the account's own sign-in (0.74.0,
|
|
50
|
+
// robin 11-17, `bookingAuth`): linked where the backend says it must be.
|
|
50
51
|
//
|
|
51
52
|
// ⚠️ FORWARDED PHISHING (Nexva's review P1-1): a link passed on to someone else
|
|
52
53
|
// signs THEIR account into the conversation it came from. Against it: the short
|
|
@@ -120,6 +121,10 @@ export const SIGN_IN_META_KEY = 'curless/account-sign-in';
|
|
|
120
121
|
export const LINK_META_KEY = 'curless/account-link';
|
|
121
122
|
export const COOKIE = '__Host-hotel_account';
|
|
122
123
|
/** How many of what, and over how long - each refusal said as "too many requests". */
|
|
124
|
+
/** Accounts whose links are remembered (`account-links.json`): the one touched longest ago goes first. */
|
|
125
|
+
const MAX_REMEMBERED_ACCOUNTS = 20_000;
|
|
126
|
+
/** Groups remembered for one account. */
|
|
127
|
+
const MAX_REMEMBERED_GROUPS = 32;
|
|
123
128
|
export const ACCOUNT_LIMITS = {
|
|
124
129
|
/** Sign-in links one conversation may ask for in ten minutes. */
|
|
125
130
|
linksPerConversation: 10,
|
|
@@ -455,6 +460,107 @@ export const makeAccount = (opts) => {
|
|
|
455
460
|
const TERMS_MS_MAX = 10 * 60_000;
|
|
456
461
|
const termsRequests = createSignIns({ now, ttlMs: TERMS_MS_MAX, perKey: 10 });
|
|
457
462
|
const termsCsrf = (r) => createHmac('sha256', secretKey).update(`terms:${r.codeHash}`).digest('base64url').slice(0, 32);
|
|
463
|
+
const remembered = new Map();
|
|
464
|
+
const clip = (v, n) => typeof v === 'string' && v.trim() ? v.trim().slice(0, n) : undefined;
|
|
465
|
+
/**
|
|
466
|
+
* ⚠️ AN EMAIL IN A GROUP'S LABEL IS MASKED BEFORE IT IS KEPT (0.74.1, 总线程's review of
|
|
467
|
+
* 0.74.0, P3): the number in it is masked already (`maskLabel`); an email beside it was not.
|
|
468
|
+
*/
|
|
469
|
+
const keptLabel = (v) => clip(typeof v === 'string'
|
|
470
|
+
? v.replace(/[^\s@()()[\]]+@[^\s@()()[\]]+/g, (m) => maskEmail(m) ?? '•••')
|
|
471
|
+
: v, 80);
|
|
472
|
+
if (linking) {
|
|
473
|
+
const saved = opts.linksFile?.read()?.accounts;
|
|
474
|
+
if (saved && typeof saved === 'object' && !Array.isArray(saved)) {
|
|
475
|
+
for (const [id, a] of Object.entries(saved)) {
|
|
476
|
+
if (remembered.size >= MAX_REMEMBERED_ACCOUNTS)
|
|
477
|
+
break;
|
|
478
|
+
if (!/^[0-9a-f]{40}$/.test(id) || !a || typeof a !== 'object')
|
|
479
|
+
continue;
|
|
480
|
+
const gs = a.groups;
|
|
481
|
+
if (!gs || typeof gs !== 'object' || Array.isArray(gs))
|
|
482
|
+
continue;
|
|
483
|
+
const groups = new Map();
|
|
484
|
+
for (const [code, g] of Object.entries(gs)) {
|
|
485
|
+
if (groups.size >= MAX_REMEMBERED_GROUPS)
|
|
486
|
+
break;
|
|
487
|
+
if (!/^[a-z0-9_-]{1,32}$/i.test(code) || !g || typeof g !== 'object')
|
|
488
|
+
continue;
|
|
489
|
+
const r = g;
|
|
490
|
+
const label = keptLabel(r.label);
|
|
491
|
+
const numberMasked = clip(r.numberMasked, 40);
|
|
492
|
+
groups.set(code.toLowerCase(), {
|
|
493
|
+
...(label ? { label } : {}),
|
|
494
|
+
...(numberMasked ? { numberMasked } : {}),
|
|
495
|
+
linkedAt: typeof r.linkedAt === 'number' && Number.isFinite(r.linkedAt) ? r.linkedAt : 0,
|
|
496
|
+
...(r.relink === true ? { relink: true } : {}),
|
|
497
|
+
});
|
|
498
|
+
}
|
|
499
|
+
const at = a.at;
|
|
500
|
+
if (groups.size)
|
|
501
|
+
remembered.set(id, { at: typeof at === 'number' ? at : 0, groups });
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
opts.linksFile?.bind(() => ({
|
|
505
|
+
v: 1,
|
|
506
|
+
accounts: Object.fromEntries([...remembered].map(([id, a]) => [id, { at: a.at, groups: Object.fromEntries(a.groups) }])),
|
|
507
|
+
}));
|
|
508
|
+
}
|
|
509
|
+
const accountIdOf = (s) => createHash('sha256')
|
|
510
|
+
.update(`account-links:${s.platform.memberUserId || s.shown.id}`)
|
|
511
|
+
.digest('hex')
|
|
512
|
+
.slice(0, 40);
|
|
513
|
+
const rememberedOf = (s, code) => s && linking ? remembered.get(accountIdOf(s))?.groups.get(code) : undefined;
|
|
514
|
+
/** This group is linked to this account, and remembered so - the flag cleared. */
|
|
515
|
+
const remember = (s, code, l) => {
|
|
516
|
+
if (!linking)
|
|
517
|
+
return;
|
|
518
|
+
const id = accountIdOf(s);
|
|
519
|
+
let a = remembered.get(id);
|
|
520
|
+
if (!a) {
|
|
521
|
+
// Full: the account touched longest ago goes first.
|
|
522
|
+
if (remembered.size >= MAX_REMEMBERED_ACCOUNTS) {
|
|
523
|
+
const oldest = [...remembered].sort((x, y) => x[1].at - y[1].at)[0];
|
|
524
|
+
if (oldest)
|
|
525
|
+
remembered.delete(oldest[0]);
|
|
526
|
+
}
|
|
527
|
+
a = { at: now(), groups: new Map() };
|
|
528
|
+
remembered.set(id, a);
|
|
529
|
+
}
|
|
530
|
+
if (!a.groups.has(code) && a.groups.size >= MAX_REMEMBERED_GROUPS)
|
|
531
|
+
return;
|
|
532
|
+
const label = keptLabel(l.label);
|
|
533
|
+
const numberMasked = clip(l.numberMasked, 40);
|
|
534
|
+
a.at = now();
|
|
535
|
+
a.groups.set(code, {
|
|
536
|
+
...(label ? { label } : {}),
|
|
537
|
+
...(numberMasked ? { numberMasked } : {}),
|
|
538
|
+
linkedAt: l.linkedAt,
|
|
539
|
+
});
|
|
540
|
+
opts.linksFile?.changed();
|
|
541
|
+
};
|
|
542
|
+
/** Unlinked: the account's record of this group is deleted. Says whether there was one. */
|
|
543
|
+
const forgetRemembered = (s, code) => {
|
|
544
|
+
const id = accountIdOf(s);
|
|
545
|
+
const a = remembered.get(id);
|
|
546
|
+
if (!a?.groups.delete(code))
|
|
547
|
+
return false;
|
|
548
|
+
if (!a.groups.size)
|
|
549
|
+
remembered.delete(id);
|
|
550
|
+
opts.linksFile?.changed();
|
|
551
|
+
return true;
|
|
552
|
+
};
|
|
553
|
+
/** The group's session is over: the record stays, flagged - the guest links again. */
|
|
554
|
+
const flagRelink = (s, code) => {
|
|
555
|
+
const r = rememberedOf(s, code);
|
|
556
|
+
if (!r)
|
|
557
|
+
return false;
|
|
558
|
+
if (!r.relink) {
|
|
559
|
+
r.relink = true;
|
|
560
|
+
opts.linksFile?.changed();
|
|
561
|
+
}
|
|
562
|
+
return true;
|
|
563
|
+
};
|
|
458
564
|
/** A linked membership, alive - one whose group session is over is dropped, as an unlink. */
|
|
459
565
|
const liveLink = (s, code) => {
|
|
460
566
|
const l = s.links?.get(code);
|
|
@@ -490,7 +596,11 @@ export const makeAccount = (opts) => {
|
|
|
490
596
|
})
|
|
491
597
|
.catch((e) => log(`[account] a membership's sign-out did not answer (${codeOf(e)})`));
|
|
492
598
|
};
|
|
493
|
-
|
|
599
|
+
/** ⚠️ THE ONE THING THAT DELETES A REMEMBERED LINK (with a link replaced by a new one). */
|
|
600
|
+
const unlink = (s, code) => {
|
|
601
|
+
const live = dropLink(s, code) !== null;
|
|
602
|
+
return forgetRemembered(s, code) || live;
|
|
603
|
+
};
|
|
494
604
|
/** "ASR Member (AS82••36)" → "ASR Member": a label with its hidden number taken out. */
|
|
495
605
|
const tierOf = (label) => label
|
|
496
606
|
.replace(/\s*[([(][^)\])]*••[^)\])]*[)\])]/g, '')
|
|
@@ -506,7 +616,12 @@ export const makeAccount = (opts) => {
|
|
|
506
616
|
* that is not its own conversation's.
|
|
507
617
|
*/
|
|
508
618
|
const membershipRows = (s, forCard, withNumber = forCard) => memberships.map((m) => {
|
|
509
|
-
const
|
|
619
|
+
const live = s ? liveLink(s, m.code) : undefined;
|
|
620
|
+
// A link remembered (0.74.0) is linked too, whichever conversation signed in - unless the
|
|
621
|
+
// group's session ended (`relink`): then the card says to link it again.
|
|
622
|
+
const mem = live ? undefined : rememberedOf(s, m.code);
|
|
623
|
+
const l = live ?? mem;
|
|
624
|
+
const relink = mem?.relink === true;
|
|
510
625
|
// The group's logo, for the card (0.61.0) - the hotel list's address; none, its initials.
|
|
511
626
|
const logoUrl = forCard ? opts.groupLogo?.(m.code) : undefined;
|
|
512
627
|
return {
|
|
@@ -514,7 +629,8 @@ export const makeAccount = (opts) => {
|
|
|
514
629
|
name: groupName(m),
|
|
515
630
|
...(m.names?.zh ? { names: { zh: m.names.zh } } : {}),
|
|
516
631
|
...(logoUrl ? { logoUrl } : {}),
|
|
517
|
-
linked: !!l,
|
|
632
|
+
linked: !!l && !relink,
|
|
633
|
+
...(relink ? { relink: true } : {}),
|
|
518
634
|
// The label has the number in it, hidden but for its ends (`maskLabel`):
|
|
519
635
|
// the model is given the tier alone (总线程 11-09: not even hidden).
|
|
520
636
|
...(l?.label && (withNumber || tierOf(l.label))
|
|
@@ -534,14 +650,17 @@ export const makeAccount = (opts) => {
|
|
|
534
650
|
return '';
|
|
535
651
|
const rows = membershipRows(s, false);
|
|
536
652
|
const linked = rows.filter((r) => r.linked);
|
|
653
|
+
const again = rows.filter((r) => r.relink);
|
|
537
654
|
const said = (code) => {
|
|
538
655
|
const m = groupOf(code);
|
|
539
656
|
return m ? groupSaid(m, noCards) : code;
|
|
540
657
|
};
|
|
541
658
|
return `Hotel memberships linked to this account: ${linked.length
|
|
542
659
|
? linked.map((r) => `${said(r.group)}${r.label ? ` · ${r.label}` : ''}`).join('; ')
|
|
543
|
-
: 'none'}.
|
|
544
|
-
.
|
|
660
|
+
: 'none'}.${again.length
|
|
661
|
+
? ` Linked before, and its session at the group ended - it may need linking again; a booking there says if it must: ${again.map((r) => `${said(r.group)}${r.label ? ` · ${r.label}` : ''}`).join('; ')}.`
|
|
662
|
+
: ''} Can be linked: ${rows
|
|
663
|
+
.filter((r) => !r.linked && !r.relink)
|
|
545
664
|
.map((r) => `${said(r.group)} (\`${r.group}\`)`)
|
|
546
665
|
.join(', ') || 'none more'} - ${names.link} gives the guest a one-time page for it.`;
|
|
547
666
|
};
|
|
@@ -1665,7 +1784,16 @@ export const makeAccount = (opts) => {
|
|
|
1665
1784
|
else if (was)
|
|
1666
1785
|
unlink(now2, m.code);
|
|
1667
1786
|
now2.links ??= new Map();
|
|
1668
|
-
|
|
1787
|
+
// ⚠️ AN EMAIL IN THE GROUP'S LABEL MASKED NOW (0.74.1): the live link is shown - and
|
|
1788
|
+
// its label read by the model - as the remembered one is, never whole.
|
|
1789
|
+
const shownLabel = keptLabel(link.label);
|
|
1790
|
+
now2.links.set(m.code, {
|
|
1791
|
+
...link,
|
|
1792
|
+
...(shownLabel ? { label: shownLabel } : {}),
|
|
1793
|
+
});
|
|
1794
|
+
// Remembered for the account (0.74.0): the next conversation, the next sign-in and a
|
|
1795
|
+
// restart show it linked - and a flag left by an ended session is cleared.
|
|
1796
|
+
remember(now2, m.code, link);
|
|
1669
1797
|
linkRequests.done(r);
|
|
1670
1798
|
log(`[account] ${tag(r.key)} linked a ${m.code} membership${up ? ' it made' : ''}`);
|
|
1671
1799
|
usage({
|
|
@@ -1792,14 +1920,17 @@ export const makeAccount = (opts) => {
|
|
|
1792
1920
|
* and the rest is not known (0.63.x); 0.66.0's orders cancelled at once say neither.
|
|
1793
1921
|
*/
|
|
1794
1922
|
const TERMS_ERRORS = {
|
|
1923
|
+
// 0.74.0 (robin 11-17): a booking needs the account's sign-in alone - on this page,
|
|
1924
|
+
// which only opens signed in, a sign-in refusal is the group's backend asking for the
|
|
1925
|
+
// membership to be linked, and a 401 the account's own sign-in over.
|
|
1795
1926
|
'sign-in': [
|
|
1796
|
-
'
|
|
1797
|
-
'
|
|
1927
|
+
'{g}需要你先关联会员才能订这一单,还没有下单。请回到对话,请助手给你关联{g}的链接,关联以后再点一次预订。',
|
|
1928
|
+
'{g} needs your membership linked before this booking can be made. Nothing was booked. Go back to your chat, ask for the link to link {g}, then press Book again.',
|
|
1798
1929
|
true,
|
|
1799
1930
|
],
|
|
1800
1931
|
'signed-out': [
|
|
1801
|
-
|
|
1802
|
-
|
|
1932
|
+
`你的 ${brand} 账号登录已经结束,没有下单。请回到对话重新登录。`,
|
|
1933
|
+
`Your sign-in to your ${brand} account has ended, and nothing was booked. Sign in again from your chat.`,
|
|
1803
1934
|
true,
|
|
1804
1935
|
],
|
|
1805
1936
|
'session-expired': [
|
|
@@ -2381,6 +2512,7 @@ export const makeAccount = (opts) => {
|
|
|
2381
2512
|
name: m ? groupIn(m, lang) : row.name,
|
|
2382
2513
|
...(logo ? { logo } : {}),
|
|
2383
2514
|
linked: row.linked,
|
|
2515
|
+
...(row.relink ? { relink: true } : {}),
|
|
2384
2516
|
...(row.label ? { label: row.label } : {}),
|
|
2385
2517
|
...(row.numberMasked ? { numberMasked: row.numberMasked } : {}),
|
|
2386
2518
|
signIn: row.signIn,
|
|
@@ -2531,18 +2663,28 @@ export const makeAccount = (opts) => {
|
|
|
2531
2663
|
},
|
|
2532
2664
|
whoOf: (key) => checked(key)?.shown.id,
|
|
2533
2665
|
memberOf: (key) => checked(key)?.platform.memberUserId,
|
|
2666
|
+
ended: (key) => {
|
|
2667
|
+
const was = store.clear(key);
|
|
2668
|
+
requests.cancelFor(key);
|
|
2669
|
+
linkRequests.cancelFor(key);
|
|
2670
|
+
termsRequests.cancelFor(key);
|
|
2671
|
+
if (!was)
|
|
2672
|
+
return;
|
|
2673
|
+
web.dropFor(was.sid);
|
|
2674
|
+
infos.forget(was.shown.id);
|
|
2675
|
+
was.links?.clear();
|
|
2676
|
+
log(`[account] ${tag(key)}: the backend refused the account's token (401) - signed out here`);
|
|
2677
|
+
},
|
|
2534
2678
|
forget: (key) => {
|
|
2535
2679
|
if (signOut(key))
|
|
2536
2680
|
log(`[account] ${tag(key)} signed out: taken over from another network`);
|
|
2537
2681
|
},
|
|
2538
2682
|
// A linked group's prices are asked for with the conversation's one token (0.72.0):
|
|
2539
2683
|
// the latest sign-in's, whichever group it was at - a link keeps none of its own.
|
|
2540
|
-
|
|
2541
|
-
|
|
2542
|
-
|
|
2543
|
-
|
|
2544
|
-
return s && liveLink(s, group) ? s.platform.access : undefined;
|
|
2545
|
-
},
|
|
2684
|
+
// ⚠️ THE SAME TOKEN AS A BOOKING'S (0.74.1, 总线程's review of 0.74.0, P2-3): the account's
|
|
2685
|
+
// own, for every group, linked or not - a price asked as anyone and booked as the member
|
|
2686
|
+
// (the 7 before 8 goes with this token) read as a price that moved, every time.
|
|
2687
|
+
tokenFor: (key, _group) => store.get(key)?.platform.access,
|
|
2546
2688
|
// The backend said the conversation's sign-in at a group is over (a 4012 to a
|
|
2547
2689
|
// price; to a booking a 401, or 4012 twice): a linked membership goes - and
|
|
2548
2690
|
// where it is the account's own sign-in (its channel, 0.62.0), the account.
|
|
@@ -2551,13 +2693,22 @@ export const makeAccount = (opts) => {
|
|
|
2551
2693
|
if (!s)
|
|
2552
2694
|
return;
|
|
2553
2695
|
const code = group.trim().toLowerCase();
|
|
2554
|
-
|
|
2696
|
+
// ⚠️ THE LINK STAYS REMEMBERED, FLAGGED (0.74.0, 总线程 11-17): a 4012 usually means the
|
|
2697
|
+
// group's session ended, not that the binding is gone. The card says to link again;
|
|
2698
|
+
// a link made again clears it; only an unlink deletes the record.
|
|
2699
|
+
const had = s.links?.delete(code);
|
|
2700
|
+
const flagged = flagRelink(s, code);
|
|
2701
|
+
if (had || flagged) {
|
|
2555
2702
|
log(`[account] ${tag(key)}: a ${code} membership's session is over`);
|
|
2556
2703
|
return;
|
|
2557
2704
|
}
|
|
2558
|
-
|
|
2559
|
-
|
|
2560
|
-
|
|
2705
|
+
// ⚠️ THE ACCOUNT'S OWN CHANNEL'S SESSION (signed in on that group - the backend before
|
|
2706
|
+
// the 11-16 document, or `signInProvider`): over, and only that - the account's token
|
|
2707
|
+
// books every group (0.74.0), so it is not signed out; its session id goes, and the
|
|
2708
|
+
// next call makes a new one (16).
|
|
2709
|
+
if (s.platform.provider === code && s.platform.mcpSessionId) {
|
|
2710
|
+
log(`[account] ${tag(key)}: the account's own ${code} session is over - a new one next time`);
|
|
2711
|
+
s.platform.mcpSessionId = undefined;
|
|
2561
2712
|
}
|
|
2562
2713
|
},
|
|
2563
2714
|
// ⚠️ THE CONVERSATION'S OWN SIGN-IN AT THAT GROUP (see `Account.bookingAuth`).
|
|
@@ -2578,18 +2729,18 @@ export const makeAccount = (opts) => {
|
|
|
2578
2729
|
...(l.mcpSessionId ? { mcpSessionId: l.mcpSessionId } : {}),
|
|
2579
2730
|
account,
|
|
2580
2731
|
};
|
|
2581
|
-
|
|
2582
|
-
|
|
2583
|
-
|
|
2584
|
-
|
|
2585
|
-
|
|
2586
|
-
|
|
2587
|
-
|
|
2588
|
-
return undefined;
|
|
2589
|
-
}
|
|
2732
|
+
// ⚠️ THE ACCOUNT'S OWN SIGN-IN BOOKS EVERY GROUP (0.74.0, robin 11-17: 「登陆平台就好,酒店
|
|
2733
|
+
// 预订不需要每次登陆」): no group is asked to be linked before it is booked - its token
|
|
2734
|
+
// goes, and the backend finds the group's linked credentials itself (its document:
|
|
2735
|
+
// 「memberToken 为空时从 Redis 渠道凭据包取绑定的 mcpToken」, questions #78). Where it
|
|
2736
|
+
// says the group is not linked (its 4012 again after a handshake, or its own words),
|
|
2737
|
+
// booking.ts asks for the link then. The `Mcp-Session-Id`: a live link's, the account's
|
|
2738
|
+
// own where it signed in on that group's channel, else none - booking.ts makes one (16).
|
|
2590
2739
|
return {
|
|
2591
2740
|
token: s.platform.access,
|
|
2592
|
-
...(s.platform.
|
|
2741
|
+
...(s.platform.provider === code && s.platform.mcpSessionId
|
|
2742
|
+
? { mcpSessionId: s.platform.mcpSessionId }
|
|
2743
|
+
: {}),
|
|
2593
2744
|
account,
|
|
2594
2745
|
};
|
|
2595
2746
|
},
|