@curless/hotel-storefront 0.81.0 → 0.82.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/addon-pages.d.ts +22 -0
- package/dist/account/addon-pages.d.ts.map +1 -0
- package/dist/account/addon-pages.js +282 -0
- package/dist/account/addon-pages.js.map +1 -0
- package/dist/account/index.d.ts +40 -0
- package/dist/account/index.d.ts.map +1 -1
- package/dist/account/index.js +444 -46
- package/dist/account/index.js.map +1 -1
- package/dist/account/ota-member.d.ts +15 -0
- package/dist/account/ota-member.d.ts.map +1 -1
- package/dist/account/ota-member.js +29 -5
- package/dist/account/ota-member.js.map +1 -1
- package/dist/account/pages.d.ts +28 -3
- package/dist/account/pages.d.ts.map +1 -1
- package/dist/account/pages.js +99 -35
- package/dist/account/pages.js.map +1 -1
- package/dist/account/requests.d.ts +11 -1
- package/dist/account/requests.d.ts.map +1 -1
- package/dist/account/requests.js +2 -1
- package/dist/account/requests.js.map +1 -1
- package/dist/backend.d.ts +7 -0
- package/dist/backend.d.ts.map +1 -1
- package/dist/backend.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/config.d.ts +4 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +12 -5
- package/dist/config.js.map +1 -1
- package/dist/legal.d.ts.map +1 -1
- package/dist/legal.js +10 -3
- package/dist/legal.js.map +1 -1
- package/dist/otaless/addons-answers.d.ts +17 -0
- package/dist/otaless/addons-answers.d.ts.map +1 -0
- package/dist/otaless/addons-answers.js +170 -0
- package/dist/otaless/addons-answers.js.map +1 -0
- package/dist/otaless/addons.d.ts +218 -0
- package/dist/otaless/addons.d.ts.map +1 -0
- package/dist/otaless/addons.js +758 -0
- package/dist/otaless/addons.js.map +1 -0
- package/dist/otaless/booking.d.ts +64 -0
- package/dist/otaless/booking.d.ts.map +1 -1
- package/dist/otaless/booking.js +156 -0
- package/dist/otaless/booking.js.map +1 -1
- package/dist/otaless/client.d.ts +2 -0
- package/dist/otaless/client.d.ts.map +1 -1
- package/dist/otaless/client.js.map +1 -1
- package/dist/otaless/fake.d.ts +22 -0
- package/dist/otaless/fake.d.ts.map +1 -1
- package/dist/otaless/fake.js +40 -7
- package/dist/otaless/fake.js.map +1 -1
- package/dist/otaless/make.d.ts +4 -3
- package/dist/otaless/make.d.ts.map +1 -1
- package/dist/otaless/make.js +21 -7
- package/dist/otaless/make.js.map +1 -1
- package/dist/otaless/shop-answers.d.ts +19 -6
- package/dist/otaless/shop-answers.d.ts.map +1 -1
- package/dist/otaless/shop-answers.js +60 -26
- package/dist/otaless/shop-answers.js.map +1 -1
- package/dist/otaless/shop-fake.d.ts +31 -1
- package/dist/otaless/shop-fake.d.ts.map +1 -1
- package/dist/otaless/shop-fake.js +79 -3
- package/dist/otaless/shop-fake.js.map +1 -1
- package/dist/otaless/shop-service.d.ts +12 -6
- package/dist/otaless/shop-service.d.ts.map +1 -1
- package/dist/otaless/shop-service.js +15 -7
- package/dist/otaless/shop-service.js.map +1 -1
- package/dist/otaless/shop.d.ts +18 -9
- package/dist/otaless/shop.d.ts.map +1 -1
- package/dist/otaless/shop.js +95 -17
- package/dist/otaless/shop.js.map +1 -1
- package/dist/server.d.ts +1 -1
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +49 -5
- package/dist/server.js.map +1 -1
- package/dist/surface.js +2 -2
- package/dist/surface.js.map +1 -1
- package/dist/tools.d.ts +132 -13
- package/dist/tools.d.ts.map +1 -1
- package/dist/tools.js +268 -97
- package/dist/tools.js.map +1 -1
- package/package.json +1 -1
package/dist/account/index.js
CHANGED
|
@@ -2,10 +2,12 @@ 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
|
+
import { ADDON_TICKET_MS } from '../otaless/addons.js';
|
|
5
6
|
import { withTrip } from '../trip-ids.js';
|
|
7
|
+
import { addonDonePage, addonPage, addonStatePage } from './addon-pages.js';
|
|
6
8
|
import { AccountInfos } from './info-cache.js';
|
|
7
9
|
import { maskEmail } from './mask.js';
|
|
8
|
-
import { LIMITS, OTA_PATHS, OtaMemberError, linkOf, makeOtaMembers, maskLabel, maskNumber, } from './ota-member.js';
|
|
10
|
+
import { ADDON_PATHS, LIMITS, OTA_PATHS, OtaMemberError, linkOf, makeOtaMembers, maskLabel, maskNumber, } from './ota-member.js';
|
|
9
11
|
import { PAGE_HEADERS, accountPage, linkGroupPage, linkReauthPage, linkedPage, loginPage, say, signedInPage, statePage, termsDonePage, termsPage, termsStatePage, } from './pages.js';
|
|
10
12
|
import { CODE, createSignIns, hashOf, same, } from './requests.js';
|
|
11
13
|
import { AccountStore, WEB_IDLE_MS, WebSessions, nameShown, nicknameOf, profileOf, profileShown, shownOf, } from './store.js';
|
|
@@ -384,6 +386,17 @@ export const makeAccount = (opts) => {
|
|
|
384
386
|
...(opts.fetch ? { fetch: opts.fetch } : {}),
|
|
385
387
|
now,
|
|
386
388
|
});
|
|
389
|
+
// The add-on shop's sign-in, register and sign-out (0.82.0): the same calls, on `/addon/*`.
|
|
390
|
+
const addonOta = makeOtaMembers({
|
|
391
|
+
baseUrl,
|
|
392
|
+
tenant,
|
|
393
|
+
...(opts.fetch ? { fetch: opts.fetch } : {}),
|
|
394
|
+
now,
|
|
395
|
+
paths: ADDON_PATHS,
|
|
396
|
+
addon: true,
|
|
397
|
+
});
|
|
398
|
+
/** The service a membership entry is linked through: the shop's own for `via: "addon"`. */
|
|
399
|
+
const otaOf = (code) => (addonMember && code === addonMember.code ? addonOta : ota);
|
|
387
400
|
const log = opts.log ?? ((l) => console.log(l));
|
|
388
401
|
// The account's own membership - its level, points, growth points (0.73.0, `/ota/info`):
|
|
389
402
|
// by account, a few minutes, and within their limit by IP (info-cache.ts).
|
|
@@ -443,6 +456,16 @@ export const makeAccount = (opts) => {
|
|
|
443
456
|
// offered, drawn or said - the tools, the card and the pages are as 0.57.1.
|
|
444
457
|
const memberships = (opts.account.memberships ?? []).filter((m) => typeof m?.code === 'string' && /^[a-z0-9_-]{1,32}$/i.test(m.code));
|
|
445
458
|
const linking = memberships.length > 0;
|
|
459
|
+
// ⚠️ `via` IS CHECKED AT THE START: a misspelt one would link a shop account through the hotel
|
|
460
|
+
// paths (or the other way about) and say nothing.
|
|
461
|
+
for (const m of opts.account.memberships ?? []) {
|
|
462
|
+
const via = m?.via;
|
|
463
|
+
if (via !== undefined && via !== 'addon')
|
|
464
|
+
throw new Error(`${opts.brand}: account.memberships "${String(m?.code)}" has via ${JSON.stringify(via)}: only "addon" is known`);
|
|
465
|
+
}
|
|
466
|
+
if (memberships.filter((m) => m.via === 'addon').length > 1)
|
|
467
|
+
throw new Error(`${opts.brand}: account.memberships has more than one via "addon" entry`);
|
|
468
|
+
const addonMember = memberships.find((m) => m.via === 'addon');
|
|
446
469
|
const groupOf = (code) => typeof code === 'string'
|
|
447
470
|
? memberships.find((m) => m.code.toLowerCase() === code.trim().toLowerCase())
|
|
448
471
|
: undefined;
|
|
@@ -480,6 +503,9 @@ export const makeAccount = (opts) => {
|
|
|
480
503
|
const TERMS_MS_MAX = 10 * 60_000;
|
|
481
504
|
const termsRequests = createSignIns({ now, ttlMs: TERMS_MS_MAX, perKey: 10 });
|
|
482
505
|
const termsCsrf = (r) => createHmac('sha256', secretKey).update(`terms:${r.codeHash}`).digest('base64url').slice(0, 32);
|
|
506
|
+
// …and one for an add-on's confirm (0.82.0): used once, ten minutes at most.
|
|
507
|
+
const addonRequests = createSignIns({ now, ttlMs: ADDON_TICKET_MS, perKey: 10 });
|
|
508
|
+
const addonCsrf = (r) => createHmac('sha256', secretKey).update(`addon:${r.codeHash}`).digest('base64url').slice(0, 32);
|
|
483
509
|
const remembered = new Map();
|
|
484
510
|
const clip = (v, n) => typeof v === 'string' && v.trim() ? v.trim().slice(0, n) : undefined;
|
|
485
511
|
/**
|
|
@@ -665,11 +691,11 @@ export const makeAccount = (opts) => {
|
|
|
665
691
|
* ⚠️ NEVER A REASON TO KEEP OUR LINK (0.79.1): the caller has forgotten it already; false says
|
|
666
692
|
* the group may still hold the old session, for the guest to be told.
|
|
667
693
|
*/
|
|
668
|
-
const endAtBackend = (code, input) =>
|
|
694
|
+
const endAtBackend = (code, input) => otaOf(code)
|
|
669
695
|
.signOut({ group: code, ...input })
|
|
670
696
|
.then(() => true)
|
|
671
697
|
.catch((e) => {
|
|
672
|
-
log(`[account] a ${code} membership's sign-out did not answer (${codeOf(e)}) -
|
|
698
|
+
log(`[account] a ${code} membership's sign-out did not answer (${codeOf(e)}) - ${addonMember && code === addonMember.code ? ADDON_PATHS.signOut : OTA_PATHS.signOut}`);
|
|
673
699
|
return false;
|
|
674
700
|
});
|
|
675
701
|
/**
|
|
@@ -692,6 +718,37 @@ export const makeAccount = (opts) => {
|
|
|
692
718
|
return { was: forgetRemembered(s, code) || live, ended };
|
|
693
719
|
};
|
|
694
720
|
const unlink = (s, code) => unlinkWith(s, code).was;
|
|
721
|
+
/**
|
|
722
|
+
* A group's sign-in kept as the conversation's link (the link page's, and the shop's signed in
|
|
723
|
+
* with the account, 0.82.1). ⚠️ THE GROUP'S TOKEN IS THE CONVERSATION'S TOKEN FROM NOW ON (0.72.0,
|
|
724
|
+
* 总线程 11-16 - the 11-16 document: 「以最后登录的 access token 为准,会覆盖前面的」): every call
|
|
725
|
+
* after - the account's own channel, every linked group's prices and bookings, an unlink, the
|
|
726
|
+
* sign-out - carries this one. An older token may be void: kept per group, linking Atour sent
|
|
727
|
+
* Ascott's booking an old token (401, and the whole account signed out), and linking a second
|
|
728
|
+
* group lost the first. Where the backend handed back the same token (the document before: one
|
|
729
|
+
* local session, renewed to the longest), the account lasts as long as the longer; a new token
|
|
730
|
+
* lasts as long as its own sign-in said.
|
|
731
|
+
*/
|
|
732
|
+
const takeLink = (s, code, session, link) => {
|
|
733
|
+
const renewed = session.access === s.platform.access;
|
|
734
|
+
s.platform.access = session.access;
|
|
735
|
+
s.platform.expires = renewed ? Math.max(s.platform.expires, session.expires) : session.expires;
|
|
736
|
+
// A link there already is replaced - its session ended (with the token just taken, as every
|
|
737
|
+
// unlink) only where it is not the one just signed in (one session, their document).
|
|
738
|
+
const was = s.links?.get(code);
|
|
739
|
+
if (was?.session && was.session === link.session)
|
|
740
|
+
s.links?.delete(code);
|
|
741
|
+
else if (was)
|
|
742
|
+
unlink(s, code);
|
|
743
|
+
s.links ??= new Map();
|
|
744
|
+
// ⚠️ AN EMAIL IN THE GROUP'S LABEL MASKED NOW (0.74.1): the live link is shown - and its label
|
|
745
|
+
// read by the model - as the remembered one is, never whole.
|
|
746
|
+
const shownLabel = keptLabel(link.label);
|
|
747
|
+
s.links.set(code, { ...link, ...(shownLabel ? { label: shownLabel } : {}) });
|
|
748
|
+
// Remembered for the account (0.74.0): the next conversation, the next sign-in and a restart
|
|
749
|
+
// show it linked - and a flag left by an ended session is cleared.
|
|
750
|
+
remember(s, code, link);
|
|
751
|
+
};
|
|
695
752
|
/** "ASR Member (AS82••36)" → "ASR Member": a label with its hidden number taken out. */
|
|
696
753
|
const tierOf = (label) => label
|
|
697
754
|
.replace(/\s*[([(][^)\])]*••[^)\])]*[)\])]/g, '')
|
|
@@ -706,7 +763,12 @@ export const makeAccount = (opts) => {
|
|
|
706
763
|
* tier alone - what the model is given, and what a card is given by a call
|
|
707
764
|
* that is not its own conversation's.
|
|
708
765
|
*/
|
|
709
|
-
const membershipRows = (s, forCard, withNumber = forCard) =>
|
|
766
|
+
const membershipRows = (s, forCard, withNumber = forCard) =>
|
|
767
|
+
// ⚠️ NOT THE SHOP (0.82.1, robin 11-23: 「不用单独再注册和关联商城,这个商城应该登陆平台就能用」):
|
|
768
|
+
// it signs in with the account itself (`shopWithAccount`), so there is no row to link it from.
|
|
769
|
+
memberships
|
|
770
|
+
.filter((m) => m.via !== 'addon')
|
|
771
|
+
.map((m) => {
|
|
710
772
|
const live = s ? liveLink(s, m.code) : undefined;
|
|
711
773
|
// A link remembered (0.74.0) is linked too, whichever conversation signed in - unless the
|
|
712
774
|
// group's session ended (`relink`): then the card says to link it again.
|
|
@@ -736,6 +798,8 @@ export const makeAccount = (opts) => {
|
|
|
736
798
|
: {}),
|
|
737
799
|
signIn: m.signIn !== false,
|
|
738
800
|
join: m.join === true,
|
|
801
|
+
// 0.82.0: the shop account is worded as an account by the card and the page (`via: "addon"`).
|
|
802
|
+
...(m.via === 'addon' ? { kind: 'shop' } : {}),
|
|
739
803
|
};
|
|
740
804
|
});
|
|
741
805
|
const membershipsSaid = (s, noCards) => {
|
|
@@ -755,7 +819,9 @@ export const makeAccount = (opts) => {
|
|
|
755
819
|
: ''} Can be linked: ${rows
|
|
756
820
|
.filter((r) => !r.linked && !r.relink)
|
|
757
821
|
.map((r) => `${said(r.group)} (\`${r.group}\`)`)
|
|
758
|
-
.join(', ') || 'none more'} - ${names.link} gives the guest a one-time page for it
|
|
822
|
+
.join(', ') || 'none more'} - ${names.link} gives the guest a one-time page for it.${addonMember
|
|
823
|
+
? ` The ${groupName(addonMember)} signs in with this ${brand} account itself - nothing to link: ${liveLink(s, addonMember.code) ? 'signed in now' : `not signed in just now (its sign-in lasts a day, or did not go through when the guest signed in); the guest signs out (${names.signOut}) and signs in again (${names.signIn}), and the shop signs in with it`}.`
|
|
824
|
+
: ''}`;
|
|
759
825
|
};
|
|
760
826
|
// ── Signing in and out ───────────────────────────────────────────────────
|
|
761
827
|
/** Signed in now, for this conversation: whatever was there before is ended. */
|
|
@@ -791,6 +857,12 @@ export const makeAccount = (opts) => {
|
|
|
791
857
|
* did not answer at all is not asked again. Never throws; nothing waits for it.
|
|
792
858
|
*/
|
|
793
859
|
const signOutAll = async (token, own, each = []) => {
|
|
860
|
+
// The shop's session is the shop's own: ended on its path, first, while the token is good.
|
|
861
|
+
await Promise.allSettled(each
|
|
862
|
+
.filter((l) => addonMember && l.group === addonMember.code)
|
|
863
|
+
.map((l) => addonOta
|
|
864
|
+
.signOut({ group: l.group, ...(l.session ? { session: l.session } : {}), auth: token })
|
|
865
|
+
.catch((e) => log(`[account] the shop's sign-out did not answer (${codeOf(e)})`))));
|
|
794
866
|
try {
|
|
795
867
|
await ota.signOut({ auth: token });
|
|
796
868
|
return;
|
|
@@ -802,7 +874,7 @@ export const makeAccount = (opts) => {
|
|
|
802
874
|
}
|
|
803
875
|
log(`[account] signing out every channel at once was refused (${codeOf(e)}): one at a time`);
|
|
804
876
|
}
|
|
805
|
-
await Promise.allSettled(each.map((l) =>
|
|
877
|
+
await Promise.allSettled(each.map((l) => otaOf(l.group)
|
|
806
878
|
.signOut({ group: l.group, ...(l.session ? { session: l.session } : {}), auth: token })
|
|
807
879
|
.catch((e) => log(`[account] a membership's sign-out did not answer (${codeOf(e)})`))));
|
|
808
880
|
// The platform's own sign-in (no channel) has no channel session of its own to end.
|
|
@@ -898,6 +970,69 @@ export const makeAccount = (opts) => {
|
|
|
898
970
|
log(`[account] ${who}: the account signed in on ${FALLBACK_SIGN_IN_PROVIDER} (the fallback)`);
|
|
899
971
|
return got;
|
|
900
972
|
};
|
|
973
|
+
/**
|
|
974
|
+
* ⚠️ THE SHOP SIGNS IN WITH THE ACCOUNT (0.82.1, robin 11-23: 「注册 otaless 调用 … 和
|
|
975
|
+
* /api/v1/addon/register,登陆调用 … 和 /api/v1/addon/sign-in,他们两个的token是一样的,不用单独再
|
|
976
|
+
* 注册和关联商城,这个商城应该登陆平台就能用」). Right after the account's own sign-in on our page,
|
|
977
|
+
* with the same email and password the guest just typed there - never kept, never logged: the
|
|
978
|
+
* shop's channel is signed in (`/addon/sign-in`, `providerCode` the shop's), its session kept as
|
|
979
|
+
* the shop's link. No shop account by that email yet (an account made before the shop was on):
|
|
980
|
+
* one is made with them (`/addon/register`) and signed in once more - unless one was made just
|
|
981
|
+
* now (`made`), which is not made twice. ⚠️ NEVER IN THE ACCOUNT'S WAY: whatever the shop says,
|
|
982
|
+
* the account is signed in; a shop that did not sign in says so later (the shop's own
|
|
983
|
+
* `sign_in_required`), and the log has the code. Nothing of the guest's is logged.
|
|
984
|
+
*/
|
|
985
|
+
/** The shop that signs in with the account, by name in the page's language (the sign-in page says it). */
|
|
986
|
+
const shopNamed = (lang) => addonMember ? { shop: (lang === 'zh' && addonMember.names?.zh) || addonMember.name } : {};
|
|
987
|
+
const shopWithAccount = async (key, email, password, lang, made) => {
|
|
988
|
+
if (!addonMember || !email || !password)
|
|
989
|
+
return;
|
|
990
|
+
const code = addonMember.code;
|
|
991
|
+
const at = store.get(key);
|
|
992
|
+
if (!at)
|
|
993
|
+
return;
|
|
994
|
+
const sid = at.sid;
|
|
995
|
+
const signIn = () => addonOta.signIn({ group: code, identity: email, password, auth: at.platform.access, lang });
|
|
996
|
+
let got;
|
|
997
|
+
try {
|
|
998
|
+
got = await signIn();
|
|
999
|
+
}
|
|
1000
|
+
catch (e) {
|
|
1001
|
+
if (notThere(e) || made?.tried) {
|
|
1002
|
+
logRefused(`[account] ${tag(key)}: the shop did not sign in with the account (${codeOf(e)})`, e);
|
|
1003
|
+
return;
|
|
1004
|
+
}
|
|
1005
|
+
logRefused(`[account] ${tag(key)}: the shop did not sign in with the account (${codeOf(e)}) - making its shop account once`, e);
|
|
1006
|
+
try {
|
|
1007
|
+
await addonOta.register({
|
|
1008
|
+
group: code,
|
|
1009
|
+
name: made?.name ?? '',
|
|
1010
|
+
email,
|
|
1011
|
+
password,
|
|
1012
|
+
auth: at.platform.access,
|
|
1013
|
+
});
|
|
1014
|
+
got = await signIn();
|
|
1015
|
+
}
|
|
1016
|
+
catch (e2) {
|
|
1017
|
+
logRefused(`[account] ${tag(key)}: no shop account made or signed in (${codeOf(e2)})`, e2);
|
|
1018
|
+
return;
|
|
1019
|
+
}
|
|
1020
|
+
}
|
|
1021
|
+
if (!got.session.mcpToken) {
|
|
1022
|
+
log(`[account] ${tag(key)}: the shop's sign-in gave no channel token - not kept`);
|
|
1023
|
+
return;
|
|
1024
|
+
}
|
|
1025
|
+
// Still that sign-in, after the shop kept us waiting? Else its session ends, unkept.
|
|
1026
|
+
const now2 = store.get(key);
|
|
1027
|
+
if (!now2 || now2.sid !== sid) {
|
|
1028
|
+
addonOta
|
|
1029
|
+
.signOut({ group: code, session: got.session.mcpToken, auth: got.session.access })
|
|
1030
|
+
.catch(() => { });
|
|
1031
|
+
return;
|
|
1032
|
+
}
|
|
1033
|
+
takeLink(now2, code, got.session, linkOf(code, got.session, got.profile, now()));
|
|
1034
|
+
log(`[account] ${tag(key)}: the shop signed in with the account`);
|
|
1035
|
+
};
|
|
901
1036
|
/**
|
|
902
1037
|
* The conversation's sign-in, while its session stands. ⚠️ NOTHING TO ASK THE
|
|
903
1038
|
* BACKEND ANY MORE (0.62.0): their `/ota/*` has no /member/info and no refresh
|
|
@@ -1174,7 +1309,17 @@ export const makeAccount = (opts) => {
|
|
|
1174
1309
|
const linkAnswer = async (args, call) => {
|
|
1175
1310
|
const { key, noCards } = call;
|
|
1176
1311
|
const m = groupOf(args.group);
|
|
1177
|
-
const listed = memberships
|
|
1312
|
+
const listed = memberships
|
|
1313
|
+
.filter((x) => x.via !== 'addon')
|
|
1314
|
+
.map((x) => `\`${x.code}\` (${groupSaid(x, noCards)})`)
|
|
1315
|
+
.join(', ');
|
|
1316
|
+
// ⚠️ THE SHOP IS NOT LINKED (0.82.1): it signs in with the account itself.
|
|
1317
|
+
if (m && m.via === 'addon')
|
|
1318
|
+
return {
|
|
1319
|
+
text: `The ${groupSaid(m, noCards)} signs in with the ${brand} account itself - there is nothing to link. If the shop says it needs a sign-in, the guest signs out (${names.signOut}) and signs in again (${names.signIn}); the shop signs in with it. The ones that can be linked: ${listed}.`,
|
|
1320
|
+
structured: { view: 'error', brand, code: 'shop_signs_in_with_account' },
|
|
1321
|
+
isError: true,
|
|
1322
|
+
};
|
|
1178
1323
|
if (!m)
|
|
1179
1324
|
return {
|
|
1180
1325
|
text: `No such hotel group to link here. The ones that can be linked: ${listed}.`,
|
|
@@ -1182,10 +1327,13 @@ export const makeAccount = (opts) => {
|
|
|
1182
1327
|
isError: true,
|
|
1183
1328
|
};
|
|
1184
1329
|
const g = groupSaid(m, noCards);
|
|
1330
|
+
// The shop's account (0.82.0, `via: "addon"`) is an account, not a hotel membership: said so.
|
|
1331
|
+
const shopAcct = !!addonMember && m.code === addonMember.code;
|
|
1332
|
+
const kind = shopAcct ? 'account' : 'membership';
|
|
1185
1333
|
const s = checked(key);
|
|
1186
1334
|
if (!s)
|
|
1187
1335
|
return {
|
|
1188
|
-
text: `Linking a ${g}
|
|
1336
|
+
text: `Linking a ${g} ${kind} 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)}.`,
|
|
1189
1337
|
structured: { view: 'account', brand, signedIn: false, code: 'not_signed_in' },
|
|
1190
1338
|
};
|
|
1191
1339
|
const mode = args.mode === 'unlink' ? 'unlink' : args.mode === 'join' ? 'up' : 'in';
|
|
@@ -1205,18 +1353,18 @@ export const makeAccount = (opts) => {
|
|
|
1205
1353
|
? { structured: { ...answer.structured, unlinkNote: 'group-session-may-remain' } }
|
|
1206
1354
|
: {}),
|
|
1207
1355
|
text: was
|
|
1208
|
-
? `The ${g}
|
|
1209
|
-
: `No ${g}
|
|
1356
|
+
? `The ${g} ${kind} is unlinked from this ${brand} account${shopAcct ? '.' : ': its prices here are the standard ones again.'}${stale ? ` ${g} did not confirm ending its own session, so it may still hold the old one until it runs out: tell the guest, who can link ${g} again at any time.` : ''}`
|
|
1357
|
+
: `No ${g} ${kind} was linked, so nothing changed.`,
|
|
1210
1358
|
};
|
|
1211
1359
|
}
|
|
1212
1360
|
if (liveLink(s, m.code))
|
|
1213
1361
|
return {
|
|
1214
1362
|
...signedInAnswer(s, '', noCards),
|
|
1215
|
-
text: `A ${g}
|
|
1363
|
+
text: `A ${g} ${kind} is already linked to this ${brand} account. To use another, unlink it first.`,
|
|
1216
1364
|
};
|
|
1217
1365
|
if ((mode === 'up' && m.join !== true) || (mode === 'in' && m.signIn === false))
|
|
1218
1366
|
return {
|
|
1219
|
-
text: `A ${g}
|
|
1367
|
+
text: `A ${g} ${kind} cannot be ${mode === 'up' ? 'made' : 'linked'} here.`,
|
|
1220
1368
|
structured: { view: 'error', brand, code: 'not_offered' },
|
|
1221
1369
|
isError: true,
|
|
1222
1370
|
};
|
|
@@ -1258,7 +1406,11 @@ export const makeAccount = (opts) => {
|
|
|
1258
1406
|
const expiresAt = new Date(made.expiresAt).toISOString();
|
|
1259
1407
|
log(`[account] a membership link for ${tag(key)}${noCards ? ' in words' : ''}`);
|
|
1260
1408
|
usage({ key, kind: 'member', step: 'link', group: m.code, signUp: mode === 'up' });
|
|
1261
|
-
const what = mode === 'up'
|
|
1409
|
+
const what = mode === 'up'
|
|
1410
|
+
? shopAcct
|
|
1411
|
+
? `sign up for ${g} and link the new account`
|
|
1412
|
+
: `join ${g} and link the new membership`
|
|
1413
|
+
: `link their ${g} ${kind}`;
|
|
1262
1414
|
const typed = `the ${g} email and password are typed on that page, never in this chat: do not ask for, or accept, them here, and never write back one the guest typed`;
|
|
1263
1415
|
// ⚠️ NO CODE (0.61.0) - see the top of this file: the page is the account's own browser's.
|
|
1264
1416
|
const where = `The page opens only in the browser they signed in to ${brand} with; anywhere else it first asks them to sign in to that same ${brand} account again.`;
|
|
@@ -1342,6 +1494,40 @@ export const makeAccount = (opts) => {
|
|
|
1342
1494
|
expiresAt: new Date(made.expiresAt).toISOString(),
|
|
1343
1495
|
};
|
|
1344
1496
|
};
|
|
1497
|
+
/** The one-time add-on confirm's link: counted against the conversation like a membership link. */
|
|
1498
|
+
const addonLink = (key, ref, lang) => {
|
|
1499
|
+
if (!opts.addons)
|
|
1500
|
+
return undefined;
|
|
1501
|
+
const s = store.get(key);
|
|
1502
|
+
if (!s)
|
|
1503
|
+
return undefined;
|
|
1504
|
+
const c = opts.addons.pending(key, ref);
|
|
1505
|
+
if (!c)
|
|
1506
|
+
return undefined;
|
|
1507
|
+
if (counters.links.count(`link:${key}`) >= ACCOUNT_LIMITS.linksPerConversation) {
|
|
1508
|
+
refusals.links++;
|
|
1509
|
+
return undefined;
|
|
1510
|
+
}
|
|
1511
|
+
const ends = Date.parse(c.until);
|
|
1512
|
+
if (!Number.isFinite(ends) || ends <= now())
|
|
1513
|
+
return undefined;
|
|
1514
|
+
const l = langOf(lang);
|
|
1515
|
+
const made = addonRequests.create({
|
|
1516
|
+
key,
|
|
1517
|
+
...(l ? { lang: l } : {}),
|
|
1518
|
+
words: true,
|
|
1519
|
+
addon: { ref, sid: s.sid },
|
|
1520
|
+
});
|
|
1521
|
+
if (!made)
|
|
1522
|
+
return undefined;
|
|
1523
|
+
counters.links.add(`link:${key}`);
|
|
1524
|
+
made.request.expires = Math.min(made.request.expires, ends);
|
|
1525
|
+
log(`[account] an add-on confirm link for ${tag(key)}`);
|
|
1526
|
+
return {
|
|
1527
|
+
url: `${publicUrl}/account?addon=${made.code}${l ? `&lang=${l}` : ''}`,
|
|
1528
|
+
expiresAt: new Date(made.request.expires).toISOString(),
|
|
1529
|
+
};
|
|
1530
|
+
};
|
|
1345
1531
|
const handle = async (name, args, call) => {
|
|
1346
1532
|
const { key, noCards } = call;
|
|
1347
1533
|
// The card's own: the same three, by `action`.
|
|
@@ -1577,7 +1763,10 @@ export const makeAccount = (opts) => {
|
|
|
1577
1763
|
name: names.link,
|
|
1578
1764
|
// ⚠️ NOTHING ABOUT THE GUEST IS ASKED FOR HERE - the group's email and
|
|
1579
1765
|
// password are typed on our page, never in the chat.
|
|
1580
|
-
description: `Links one hotel group's loyalty membership to the guest's ${brand} account - or joins that group and links the new membership - on ${brand}'s own web page: answers with a one-time link, which opens in the browser the guest signed in to ${brand} with - or unlinks it at once (mode unlink), with no page: the link is removed and that group's session ends. Needs the guest signed in to ${brand}. Takes no personal details. Groups: ${memberships
|
|
1766
|
+
description: `Links one hotel group's loyalty membership to the guest's ${brand} account - or joins that group and links the new membership - on ${brand}'s own web page: answers with a one-time link, which opens in the browser the guest signed in to ${brand} with - or unlinks it at once (mode unlink), with no page: the link is removed and that group's session ends. Needs the guest signed in to ${brand}. Takes no personal details. Groups: ${memberships
|
|
1767
|
+
.filter((m) => m.via !== 'addon')
|
|
1768
|
+
.map((m) => `\`${m.code}\` (${groupName(m)})`)
|
|
1769
|
+
.join(', ')}.${addonMember ? ` The ${groupName(addonMember)} is not linked here: it signs in with the ${brand} account itself.` : ''}`,
|
|
1581
1770
|
annotations: {
|
|
1582
1771
|
title: 'Link a hotel membership',
|
|
1583
1772
|
readOnlyHint: false,
|
|
@@ -1591,7 +1780,7 @@ export const makeAccount = (opts) => {
|
|
|
1591
1780
|
properties: {
|
|
1592
1781
|
group: {
|
|
1593
1782
|
type: 'string',
|
|
1594
|
-
enum: memberships.map((m) => m.code),
|
|
1783
|
+
enum: memberships.filter((m) => m.via !== 'addon').map((m) => m.code),
|
|
1595
1784
|
description: 'The hotel group, by its code',
|
|
1596
1785
|
},
|
|
1597
1786
|
mode: {
|
|
@@ -1635,7 +1824,14 @@ export const makeAccount = (opts) => {
|
|
|
1635
1824
|
],
|
|
1636
1825
|
},
|
|
1637
1826
|
lang: { type: 'string', enum: ['zh', 'en'] },
|
|
1638
|
-
...(linking
|
|
1827
|
+
...(linking
|
|
1828
|
+
? {
|
|
1829
|
+
group: {
|
|
1830
|
+
type: 'string',
|
|
1831
|
+
enum: memberships.filter((m) => m.via !== 'addon').map((m) => m.code),
|
|
1832
|
+
},
|
|
1833
|
+
}
|
|
1834
|
+
: {}),
|
|
1639
1835
|
...(walletPart ? walletProps() : {}),
|
|
1640
1836
|
},
|
|
1641
1837
|
required: ['action'],
|
|
@@ -1832,7 +2028,10 @@ export const makeAccount = (opts) => {
|
|
|
1832
2028
|
};
|
|
1833
2029
|
const ownerOf = (c, r) => {
|
|
1834
2030
|
const at = sessionOf(c);
|
|
1835
|
-
return at.ws &&
|
|
2031
|
+
return at.ws &&
|
|
2032
|
+
at.s &&
|
|
2033
|
+
at.ws.key === r.key &&
|
|
2034
|
+
at.s.sid === (r.link ?? r.terms ?? r.addon)?.sid
|
|
1836
2035
|
? { id: at.id, s: at.s }
|
|
1837
2036
|
: null;
|
|
1838
2037
|
};
|
|
@@ -1847,6 +2046,7 @@ export const makeAccount = (opts) => {
|
|
|
1847
2046
|
group: m ? groupIn(m, lang) : String(r.link?.group),
|
|
1848
2047
|
...(m && logoPath(m.code) ? { logo: logoPath(m.code) } : {}),
|
|
1849
2048
|
accountName: nameOf(s),
|
|
2049
|
+
...(m?.via === 'addon' ? { shop: true } : {}),
|
|
1850
2050
|
mode: mode === 'up' && m?.join === true ? 'up' : 'in',
|
|
1851
2051
|
...(error ? { error: say(lang, error, m ? groupIn(m, lang) : brand, brand) } : {}),
|
|
1852
2052
|
...(error && said ? { said } : {}),
|
|
@@ -1860,6 +2060,7 @@ export const makeAccount = (opts) => {
|
|
|
1860
2060
|
code,
|
|
1861
2061
|
csrf: linkCsrf(r),
|
|
1862
2062
|
group: m ? groupIn(m, lang) : String(r.link?.group),
|
|
2063
|
+
...(m?.via === 'addon' ? { shop: true } : {}),
|
|
1863
2064
|
...(m && logoPath(m.code) ? { logo: logoPath(m.code) } : {}),
|
|
1864
2065
|
...(error ? { error: say(lang, error, brand) } : {}),
|
|
1865
2066
|
...(error && said ? { said } : {}),
|
|
@@ -2028,7 +2229,7 @@ export const makeAccount = (opts) => {
|
|
|
2028
2229
|
let joinLabel;
|
|
2029
2230
|
if (up) {
|
|
2030
2231
|
try {
|
|
2031
|
-
({ memberNo, label: joinLabel } = await
|
|
2232
|
+
({ memberNo, label: joinLabel } = await otaOf(m.code).register({
|
|
2032
2233
|
group: m.code,
|
|
2033
2234
|
name: values.name ?? '',
|
|
2034
2235
|
email: values.email ?? '',
|
|
@@ -2051,7 +2252,7 @@ export const makeAccount = (opts) => {
|
|
|
2051
2252
|
let link;
|
|
2052
2253
|
let got;
|
|
2053
2254
|
try {
|
|
2054
|
-
got = await
|
|
2255
|
+
got = await otaOf(m.code).signIn({
|
|
2055
2256
|
group: m.code,
|
|
2056
2257
|
identity: (up ? values.email : values.identity) ?? '',
|
|
2057
2258
|
password,
|
|
@@ -2072,7 +2273,7 @@ export const makeAccount = (opts) => {
|
|
|
2072
2273
|
// ⚠️ 409 "This record already exists. Please reset and try again." (0.79.1, questions
|
|
2073
2274
|
// #99): the group still holds an old record of this link - not the password's fault.
|
|
2074
2275
|
if (recordExists(e)) {
|
|
2075
|
-
log(`[account] ${tag(r.key)}: a ${m.code} membership link answered 409, the record already exists (POST ${OTA_PATHS.signIn}) - the guest links again, support if it keeps failing`);
|
|
2276
|
+
log(`[account] ${tag(r.key)}: a ${m.code} membership link answered 409, the record already exists (POST ${m.via === 'addon' ? ADDON_PATHS.signIn : OTA_PATHS.signIn}) - the guest links again, support if it keeps failing`);
|
|
2076
2277
|
return again('link_conflict');
|
|
2077
2278
|
}
|
|
2078
2279
|
const said = saidBy(e);
|
|
@@ -2087,7 +2288,7 @@ export const makeAccount = (opts) => {
|
|
|
2087
2288
|
const now2 = store.get(r.key);
|
|
2088
2289
|
if (!now2 || now2.sid !== r.link?.sid) {
|
|
2089
2290
|
linkRequests.reopen(r);
|
|
2090
|
-
|
|
2291
|
+
otaOf(m.code)
|
|
2091
2292
|
.signOut({
|
|
2092
2293
|
group: m.code,
|
|
2093
2294
|
...(link.session ? { session: link.session } : {}),
|
|
@@ -2116,30 +2317,7 @@ export const makeAccount = (opts) => {
|
|
|
2116
2317
|
// Where the backend handed back the same token (the document before: one local
|
|
2117
2318
|
// session, renewed to the longest), the account lasts as long as the longer;
|
|
2118
2319
|
// a new token lasts as long as its own sign-in said.
|
|
2119
|
-
|
|
2120
|
-
now2.platform.access = got.session.access;
|
|
2121
|
-
now2.platform.expires = renewed
|
|
2122
|
-
? Math.max(now2.platform.expires, got.session.expires)
|
|
2123
|
-
: got.session.expires;
|
|
2124
|
-
// A link there already is replaced - its session ended (with the token just
|
|
2125
|
-
// taken, as every unlink) only where it is not the one just signed in (one
|
|
2126
|
-
// session, their document).
|
|
2127
|
-
const was = now2.links?.get(m.code);
|
|
2128
|
-
if (was?.session && was.session === link.session)
|
|
2129
|
-
now2.links?.delete(m.code);
|
|
2130
|
-
else if (was)
|
|
2131
|
-
unlink(now2, m.code);
|
|
2132
|
-
now2.links ??= new Map();
|
|
2133
|
-
// ⚠️ AN EMAIL IN THE GROUP'S LABEL MASKED NOW (0.74.1): the live link is shown - and
|
|
2134
|
-
// its label read by the model - as the remembered one is, never whole.
|
|
2135
|
-
const shownLabel = keptLabel(link.label);
|
|
2136
|
-
now2.links.set(m.code, {
|
|
2137
|
-
...link,
|
|
2138
|
-
...(shownLabel ? { label: shownLabel } : {}),
|
|
2139
|
-
});
|
|
2140
|
-
// Remembered for the account (0.74.0): the next conversation, the next sign-in and a
|
|
2141
|
-
// restart show it linked - and a flag left by an ended session is cleared.
|
|
2142
|
-
remember(now2, m.code, link);
|
|
2320
|
+
takeLink(now2, m.code, got.session, link);
|
|
2143
2321
|
linkRequests.done(r);
|
|
2144
2322
|
log(`[account] ${tag(r.key)} linked a ${m.code} membership${up ? ' it made' : ''}`);
|
|
2145
2323
|
usage({
|
|
@@ -2153,6 +2331,7 @@ export const makeAccount = (opts) => {
|
|
|
2153
2331
|
return send(c, 200, linkedPage(brandPage, {
|
|
2154
2332
|
lang,
|
|
2155
2333
|
group: groupIn(m, lang),
|
|
2334
|
+
...(m.via === 'addon' ? { shop: true } : {}),
|
|
2156
2335
|
...(link.label ? { label: link.label } : {}),
|
|
2157
2336
|
}));
|
|
2158
2337
|
}
|
|
@@ -2596,6 +2775,7 @@ export const makeAccount = (opts) => {
|
|
|
2596
2775
|
// Nothing is used up by looking: a link scanner's GET leaves it as it was.
|
|
2597
2776
|
return send(c, 200, loginPage(brandPage, {
|
|
2598
2777
|
lang,
|
|
2778
|
+
...shopNamed(lang),
|
|
2599
2779
|
short: r.short,
|
|
2600
2780
|
code,
|
|
2601
2781
|
csrf: loginCsrf(r),
|
|
@@ -2644,6 +2824,7 @@ export const makeAccount = (opts) => {
|
|
|
2644
2824
|
const password = formStr(body.password, LIMITS.password);
|
|
2645
2825
|
const again = (error, as = up ? 'up' : 'in', kept = values, said) => send(c, 200, loginPage(brandPage, {
|
|
2646
2826
|
lang,
|
|
2827
|
+
...shopNamed(lang),
|
|
2647
2828
|
short: r.short,
|
|
2648
2829
|
code,
|
|
2649
2830
|
csrf: loginCsrf(r),
|
|
@@ -2732,6 +2913,23 @@ export const makeAccount = (opts) => {
|
|
|
2732
2913
|
return again(notThere(e) ? 'busy' : 'register_failed');
|
|
2733
2914
|
}
|
|
2734
2915
|
outcome = 'ok';
|
|
2916
|
+
// The shop's account beside it (0.82.1), with the same email and password: its answer
|
|
2917
|
+
// is the log's alone - the account stands whatever the shop says.
|
|
2918
|
+
if (addonMember) {
|
|
2919
|
+
try {
|
|
2920
|
+
await addonOta.register({
|
|
2921
|
+
group: addonMember.code,
|
|
2922
|
+
name: values.nickname ?? '',
|
|
2923
|
+
email: values.email ?? '',
|
|
2924
|
+
password,
|
|
2925
|
+
auth: '',
|
|
2926
|
+
});
|
|
2927
|
+
log(`[account] a shop account was made beside the account for ${tag(r.key)}`);
|
|
2928
|
+
}
|
|
2929
|
+
catch (e) {
|
|
2930
|
+
logRefused(`[account] no shop account was made beside the account for ${tag(r.key)} (${codeOf(e)})`, e);
|
|
2931
|
+
}
|
|
2932
|
+
}
|
|
2735
2933
|
for (const ch of channels)
|
|
2736
2934
|
if (ch.memberNo && groupOf(ch.code))
|
|
2737
2935
|
signUpNumbers.set(ch.code, maskNumber(ch.memberNo));
|
|
@@ -2795,6 +2993,12 @@ export const makeAccount = (opts) => {
|
|
|
2795
2993
|
return again('busy');
|
|
2796
2994
|
}
|
|
2797
2995
|
requests.done(r);
|
|
2996
|
+
// The shop, with the same email and password (0.82.1) - before the page says signed in, so
|
|
2997
|
+
// the shop is there when the guest goes back to the chat; never in the account's way.
|
|
2998
|
+
await shopWithAccount(r.key, typed, password, lang, {
|
|
2999
|
+
tried: up,
|
|
3000
|
+
...(values.nickname ? { name: values.nickname } : {}),
|
|
3001
|
+
});
|
|
2798
3002
|
// A new trip id for the conversation (0.75.1, risk A) - never in the sign-in's way.
|
|
2799
3003
|
try {
|
|
2800
3004
|
opts.onSignedIn?.(r.key, r.codeHash);
|
|
@@ -2962,11 +3166,199 @@ export const makeAccount = (opts) => {
|
|
|
2962
3166
|
}
|
|
2963
3167
|
return send(c, 400, statePage(brandPage, lang, 'checked', plainHref('/account')));
|
|
2964
3168
|
};
|
|
3169
|
+
// ── An add-on's confirm, on its own page (0.82.0) ──────────────────────────────────────────
|
|
3170
|
+
// ⚠️ ON THE EXISTING PATH `/account`, TOLD APART BY ?addon= (Caddy passes fixed paths only).
|
|
3171
|
+
// Guarded as the terms page is: only the browser holding THIS account's sign-in opens it
|
|
3172
|
+
// (`ownerOf`), else the same account signs in again here; a POST comes from our page (Origin)
|
|
3173
|
+
// with the request's own token; one POST at a time (`begin`); used once - pressing confirm OR
|
|
3174
|
+
// leaving ends it. The press is the only thing that can send: `opts.addons.confirm` takes the
|
|
3175
|
+
// prepared confirm (one use), re-reads, and sends at most once. NOTHING OF THE ADD-ON, THE
|
|
3176
|
+
// BOOKING OR THE GUEST IS LOGGED.
|
|
3177
|
+
const addonHref = (code) => (l) => `${base}/account?addon=${encodeURIComponent(code)}&lang=${l}`;
|
|
3178
|
+
const addonState = (r) => {
|
|
3179
|
+
const st = addonRequests.state(r, false);
|
|
3180
|
+
if (st !== 'open')
|
|
3181
|
+
return st;
|
|
3182
|
+
return store.get(r.key)?.sid === r.addon?.sid ? 'open' : 'expired';
|
|
3183
|
+
};
|
|
3184
|
+
// What a pressed confirm came to, by its link (live walkthrough 11-23: a second press while the
|
|
3185
|
+
// first was at the backend left the guest on "Working on it" - the outcome, and a payment link,
|
|
3186
|
+
// went to the first request's page, which the browser had dropped). The pending page looks
|
|
3187
|
+
// again every 2 s at the link itself; once done, the SAME account's browser (`ownerOf`) is shown
|
|
3188
|
+
// the outcome there. Kept as long as the used link is (requests.ts: 30 minutes), in memory only.
|
|
3189
|
+
const addonDone = new WeakMap();
|
|
3190
|
+
const addonNotOpen = (c, code, state, lang, r) => {
|
|
3191
|
+
const done = state === 'used' && r ? addonDone.get(r) : undefined;
|
|
3192
|
+
if (done && r && ownerOf(c, r))
|
|
3193
|
+
return send(c, 200, addonDonePage(brandPage, lang, code, done, true));
|
|
3194
|
+
return send(c, state === 'pending' ? 202 : state === 'tries' ? 429 : statusOf(state), addonStatePage(brandPage, lang, state === 'used'
|
|
3195
|
+
? 'used'
|
|
3196
|
+
: state === 'pending'
|
|
3197
|
+
? 'pending'
|
|
3198
|
+
: state === 'unknown'
|
|
3199
|
+
? 'unknown'
|
|
3200
|
+
: 'expired', addonHref(code), state === 'pending' ? addonHref(code)(lang) : undefined));
|
|
3201
|
+
};
|
|
3202
|
+
const addonReauth = (c, code, r, lang, error, said) => send(c, 200, linkReauthPage(brandPage, {
|
|
3203
|
+
lang,
|
|
3204
|
+
code,
|
|
3205
|
+
csrf: addonCsrf(r),
|
|
3206
|
+
group: brand,
|
|
3207
|
+
addon: true,
|
|
3208
|
+
...(error ? { error: say(lang, error, brand) } : {}),
|
|
3209
|
+
...(error && said ? { said } : {}),
|
|
3210
|
+
}));
|
|
3211
|
+
const addonGet = (c, code) => {
|
|
3212
|
+
const r = addonRequests.find(code);
|
|
3213
|
+
const lang = langFor(c, r);
|
|
3214
|
+
if (over(c, 'pages', ipOf(c), ACCOUNT_LIMITS.pagesPerIp))
|
|
3215
|
+
return send(c, 429, statePage(brandPage, lang, 'limited', plainHref('/account')));
|
|
3216
|
+
if (!r?.addon || !opts.addons)
|
|
3217
|
+
return addonNotOpen(c, code, 'unknown', lang);
|
|
3218
|
+
const state = addonState(r);
|
|
3219
|
+
if (state !== 'open')
|
|
3220
|
+
return addonNotOpen(c, code, state, lang, r);
|
|
3221
|
+
const owner = ownerOf(c, r);
|
|
3222
|
+
if (!owner)
|
|
3223
|
+
return addonReauth(c, code, r, lang);
|
|
3224
|
+
if (owner.id)
|
|
3225
|
+
setCookie(c, owner.id);
|
|
3226
|
+
const conf = opts.addons.pending(r.key, r.addon.ref);
|
|
3227
|
+
if (!conf)
|
|
3228
|
+
return send(c, 410, addonStatePage(brandPage, lang, 'gone', addonHref(code)));
|
|
3229
|
+
return send(c, 200, addonPage(brandPage, { lang, code, csrf: addonCsrf(r), confirm: conf }));
|
|
3230
|
+
};
|
|
3231
|
+
const addonPost = async (c, body, code, lang) => {
|
|
3232
|
+
const r = addonRequests.find(code);
|
|
3233
|
+
if (!r?.addon || !opts.addons)
|
|
3234
|
+
return addonNotOpen(c, code, 'unknown', lang);
|
|
3235
|
+
const state = addonState(r);
|
|
3236
|
+
if (state !== 'open')
|
|
3237
|
+
return addonNotOpen(c, code, state, lang, r);
|
|
3238
|
+
if (!same(body.csrf, addonCsrf(r))) {
|
|
3239
|
+
refusals.csrf++;
|
|
3240
|
+
return send(c, 403, statePage(brandPage, lang, 'checked', addonHref(code)));
|
|
3241
|
+
}
|
|
3242
|
+
if (!addonRequests.tried(r)) {
|
|
3243
|
+
log(`[account] an add-on link for ${tag(r.key)} refused after too many tries`);
|
|
3244
|
+
return send(c, 429, statePage(brandPage, lang, 'tries', addonHref(code)));
|
|
3245
|
+
}
|
|
3246
|
+
const s = store.get(r.key);
|
|
3247
|
+
if (!s || s.sid !== r.addon.sid)
|
|
3248
|
+
return addonNotOpen(c, code, 'expired', lang);
|
|
3249
|
+
// The account's own sign-in, again: it proves the browser is that account's.
|
|
3250
|
+
if (body.form === 'reauth') {
|
|
3251
|
+
const account = formStr(body.account, LIMITS.account).trim();
|
|
3252
|
+
const password = formStr(body.password, LIMITS.password);
|
|
3253
|
+
if (!account || !password)
|
|
3254
|
+
return addonReauth(c, code, r, lang, 'missing_in_email');
|
|
3255
|
+
if (notAnEmail(account))
|
|
3256
|
+
return addonReauth(c, code, r, lang, 'email_only');
|
|
3257
|
+
const named = `a:${account.toLowerCase()}`;
|
|
3258
|
+
if (nameFailures.shut(named, ACCOUNT_LIMITS.perName)) {
|
|
3259
|
+
refusals.names++;
|
|
3260
|
+
return addonReauth(c, code, r, lang, 'too_many');
|
|
3261
|
+
}
|
|
3262
|
+
if (over(c, 'all', 'in', ACCOUNT_LIMITS.signInsPerMinute))
|
|
3263
|
+
return send(c, 429, statePage(brandPage, lang, 'limited', addonHref(code)));
|
|
3264
|
+
if (!addonRequests.begin(r))
|
|
3265
|
+
return addonNotOpen(c, code, 'pending', lang);
|
|
3266
|
+
if (!nameFailures.enter(named, ACCOUNT_LIMITS.perName)) {
|
|
3267
|
+
addonRequests.reopen(r);
|
|
3268
|
+
refusals.names++;
|
|
3269
|
+
return addonReauth(c, code, r, lang, 'too_many');
|
|
3270
|
+
}
|
|
3271
|
+
let proved = null;
|
|
3272
|
+
let outcome = 'unknown';
|
|
3273
|
+
try {
|
|
3274
|
+
proved = await platformSignIn(tag(r.key), account, password, lang);
|
|
3275
|
+
outcome = 'ok';
|
|
3276
|
+
}
|
|
3277
|
+
catch (e) {
|
|
3278
|
+
addonRequests.reopen(r);
|
|
3279
|
+
outcome = notThere(e) ? 'unknown' : 'failed';
|
|
3280
|
+
logRefused(`[account] a re-sign-in for an add-on link of ${tag(r.key)} refused (${codeOf(e)})`, e);
|
|
3281
|
+
const said = saidBy(e);
|
|
3282
|
+
return said
|
|
3283
|
+
? addonReauth(c, code, r, lang, 'sign_in_refused', said)
|
|
3284
|
+
: addonReauth(c, code, r, lang, notThere(e) ? 'busy' : wrong(e) ? signInFailed : 'sign_in_unconfirmed');
|
|
3285
|
+
}
|
|
3286
|
+
finally {
|
|
3287
|
+
nameFailures.leave(named, outcome);
|
|
3288
|
+
}
|
|
3289
|
+
addonRequests.reopen(r);
|
|
3290
|
+
const still = store.get(r.key);
|
|
3291
|
+
const sameTok = (p, q) => p.access === q.access || (!!p.mcpToken && p.mcpToken === q.mcpToken);
|
|
3292
|
+
const who = shownOf(proved.session, proved.profile, account);
|
|
3293
|
+
if (!still || still.sid !== r.addon.sid) {
|
|
3294
|
+
if (!still || !sameTok(proved.session, still.platform))
|
|
3295
|
+
void endSession(proved.session);
|
|
3296
|
+
return addonNotOpen(c, code, 'expired', lang);
|
|
3297
|
+
}
|
|
3298
|
+
if (who.id !== still.shown.id) {
|
|
3299
|
+
if (!sameTok(proved.session, still.platform))
|
|
3300
|
+
void endSession(proved.session);
|
|
3301
|
+
log(`[account] an add-on link of ${tag(r.key)} opened by another account: refused`);
|
|
3302
|
+
return addonReauth(c, code, r, lang, 'reauth_other');
|
|
3303
|
+
}
|
|
3304
|
+
still.platform = proved.session;
|
|
3305
|
+
// The shop again with the same email and password (0.82.1): a purchase page is where its
|
|
3306
|
+
// day-long sign-in running out would show.
|
|
3307
|
+
if (addonMember && !liveLink(still, addonMember.code))
|
|
3308
|
+
await shopWithAccount(r.key, account, password, lang);
|
|
3309
|
+
const id = web.open(r.key, still.sid);
|
|
3310
|
+
if (id)
|
|
3311
|
+
setCookie(c, id);
|
|
3312
|
+
const conf = opts.addons.pending(r.key, r.addon.ref);
|
|
3313
|
+
if (!conf)
|
|
3314
|
+
return send(c, 410, addonStatePage(brandPage, lang, 'gone', addonHref(code)));
|
|
3315
|
+
return send(c, 200, addonPage(brandPage, { lang, code, csrf: addonCsrf(r), confirm: conf }));
|
|
3316
|
+
}
|
|
3317
|
+
const owner = ownerOf(c, r);
|
|
3318
|
+
if (!owner)
|
|
3319
|
+
return addonReauth(c, code, r, lang);
|
|
3320
|
+
const action = body.action;
|
|
3321
|
+
if (action !== 'confirm' && action !== 'discard')
|
|
3322
|
+
return send(c, 400, statePage(brandPage, lang, 'checked', addonHref(code)));
|
|
3323
|
+
if (!addonRequests.begin(r))
|
|
3324
|
+
return addonNotOpen(c, code, 'pending', lang);
|
|
3325
|
+
const ref = r.addon.ref;
|
|
3326
|
+
if (action === 'discard') {
|
|
3327
|
+
opts.addons.discard(r.key, ref);
|
|
3328
|
+
r.state = 'done';
|
|
3329
|
+
r.doneAt = now();
|
|
3330
|
+
log(`[account] add-on confirm left k=${tag(r.key)}`);
|
|
3331
|
+
return send(c, 200, addonStatePage(brandPage, lang, 'gone', addonHref(code)));
|
|
3332
|
+
}
|
|
3333
|
+
// ⚠️ CONFIRM: ONE USE, WHATEVER COMES BACK - the prepared confirm is taken before anything is
|
|
3334
|
+
// sent, and so is this link.
|
|
3335
|
+
let done;
|
|
3336
|
+
try {
|
|
3337
|
+
done = await opts.addons.confirm(r.key, ref, lang);
|
|
3338
|
+
}
|
|
3339
|
+
catch {
|
|
3340
|
+
done = undefined;
|
|
3341
|
+
}
|
|
3342
|
+
r.state = 'done';
|
|
3343
|
+
r.doneAt = now();
|
|
3344
|
+
if (done)
|
|
3345
|
+
addonDone.set(r, done);
|
|
3346
|
+
if (!done) {
|
|
3347
|
+
log(`[account] add-on confirm k=${tag(r.key)} → gone`);
|
|
3348
|
+
return send(c, 410, addonStatePage(brandPage, lang, 'gone', addonHref(code)));
|
|
3349
|
+
}
|
|
3350
|
+
log(`[account] add-on confirm k=${tag(r.key)} ${done.result.action} → ${done.result.outcome}${done.result.reason ? ` (${done.result.reason})` : ''}${done.result.needsPerson ? ' NEEDS A PERSON' : ''}`);
|
|
3351
|
+
return send(c, 200, addonDonePage(brandPage, lang, code, done));
|
|
3352
|
+
};
|
|
2965
3353
|
app.get('/account', async (c) => {
|
|
2966
3354
|
// A group's booking terms, on this same path (0.63.0): told apart by the query.
|
|
2967
3355
|
const termsCode = c.req.query('terms');
|
|
2968
3356
|
if (termsCode !== undefined)
|
|
2969
3357
|
return termsGet(c, termsCode);
|
|
3358
|
+
// An add-on's confirm (0.82.0), likewise.
|
|
3359
|
+
const addonCode = c.req.query('addon');
|
|
3360
|
+
if (addonCode !== undefined)
|
|
3361
|
+
return addonGet(c, addonCode);
|
|
2970
3362
|
const lang = langFor(c);
|
|
2971
3363
|
if (over(c, 'pages', ipOf(c), ACCOUNT_LIMITS.pagesPerIp))
|
|
2972
3364
|
return send(c, 429, statePage(brandPage, lang, 'limited', plainHref('/account')));
|
|
@@ -3041,6 +3433,7 @@ export const makeAccount = (opts) => {
|
|
|
3041
3433
|
...(row.numberMasked ? { numberMasked: row.numberMasked } : {}),
|
|
3042
3434
|
signIn: row.signIn,
|
|
3043
3435
|
join: row.join,
|
|
3436
|
+
...(row.kind === 'shop' ? { kind: 'shop' } : {}),
|
|
3044
3437
|
};
|
|
3045
3438
|
}),
|
|
3046
3439
|
}
|
|
@@ -3061,6 +3454,9 @@ export const makeAccount = (opts) => {
|
|
|
3061
3454
|
// A group's booking terms (0.63.0): the form's hidden `terms` field, handled first.
|
|
3062
3455
|
if (typeof body.terms === 'string')
|
|
3063
3456
|
return termsPost(c, body, formStr(body.terms, 64), lang);
|
|
3457
|
+
// An add-on's confirm (0.82.0): the form's hidden `addon` field.
|
|
3458
|
+
if (typeof body.addon === 'string')
|
|
3459
|
+
return addonPost(c, body, formStr(body.addon, 64), lang);
|
|
3064
3460
|
const at = sessionOf(c);
|
|
3065
3461
|
if (!at.ws || !at.s) {
|
|
3066
3462
|
if (at.id)
|
|
@@ -3089,7 +3485,8 @@ export const makeAccount = (opts) => {
|
|
|
3089
3485
|
}
|
|
3090
3486
|
if (m && body.action === 'link') {
|
|
3091
3487
|
const mode = body.mode === 'up' && m.join === true ? 'up' : 'in';
|
|
3092
|
-
|
|
3488
|
+
// The shop signs in with the account (0.82.1): not linked from here.
|
|
3489
|
+
if (m.via === 'addon' || liveLink(at.s, m.code) || (mode === 'in' && m.signIn === false))
|
|
3093
3490
|
return c.redirect(`${base}/account?lang=${lang}`, 303);
|
|
3094
3491
|
if (over(c, 'links', `link:${at.ws.key}`, ACCOUNT_LIMITS.linksPerConversation))
|
|
3095
3492
|
return send(c, 429, statePage(brandPage, lang, 'limited', plainHref('/account')));
|
|
@@ -3284,6 +3681,7 @@ export const makeAccount = (opts) => {
|
|
|
3284
3681
|
},
|
|
3285
3682
|
bookingAuth,
|
|
3286
3683
|
termsLink,
|
|
3684
|
+
addonLink,
|
|
3287
3685
|
instructions,
|
|
3288
3686
|
mount,
|
|
3289
3687
|
health: () => ({
|