@curless/hotel-storefront 0.80.3 → 0.82.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.
- 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 +54 -0
- package/dist/account/index.d.ts.map +1 -1
- package/dist/account/index.js +719 -61
- 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 +21 -5
- package/dist/account/ota-member.js.map +1 -1
- package/dist/account/pages.d.ts +39 -4
- package/dist/account/pages.d.ts.map +1 -1
- package/dist/account/pages.js +104 -42
- 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/account/wallet-pages.d.ts +84 -0
- package/dist/account/wallet-pages.d.ts.map +1 -0
- package/dist/account/wallet-pages.js +229 -0
- package/dist/account/wallet-pages.js.map +1 -0
- package/dist/account/wallet.d.ts +163 -0
- package/dist/account/wallet.d.ts.map +1 -0
- package/dist/account/wallet.js +365 -0
- package/dist/account/wallet.js.map +1 -0
- package/dist/backend.d.ts +25 -0
- package/dist/backend.d.ts.map +1 -1
- package/dist/backend.js.map +1 -1
- package/dist/card-v168.generated.d.ts +6 -0
- package/dist/card-v168.generated.d.ts.map +1 -0
- package/dist/card-v168.generated.js +10 -0
- package/dist/card-v168.generated.js.map +1 -0
- 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 +51 -2
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +21 -1
- package/dist/config.js.map +1 -1
- package/dist/legal.d.ts.map +1 -1
- package/dist/legal.js +33 -4
- 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 +111 -0
- package/dist/otaless/client.d.ts.map +1 -1
- package/dist/otaless/client.js +44 -4
- package/dist/otaless/client.js.map +1 -1
- package/dist/otaless/fake.d.ts +114 -0
- package/dist/otaless/fake.d.ts.map +1 -1
- package/dist/otaless/fake.js +305 -7
- package/dist/otaless/fake.js.map +1 -1
- package/dist/otaless/make.d.ts +41 -1
- package/dist/otaless/make.d.ts.map +1 -1
- package/dist/otaless/make.js +165 -2
- package/dist/otaless/make.js.map +1 -1
- package/dist/otaless/shop-answers.d.ts +81 -0
- package/dist/otaless/shop-answers.d.ts.map +1 -0
- package/dist/otaless/shop-answers.js +378 -0
- package/dist/otaless/shop-answers.js.map +1 -0
- package/dist/otaless/shop-client.d.ts +133 -0
- package/dist/otaless/shop-client.d.ts.map +1 -0
- package/dist/otaless/shop-client.js +201 -0
- package/dist/otaless/shop-client.js.map +1 -0
- package/dist/otaless/shop-fake.d.ts +130 -0
- package/dist/otaless/shop-fake.d.ts.map +1 -0
- package/dist/otaless/shop-fake.js +335 -0
- package/dist/otaless/shop-fake.js.map +1 -0
- package/dist/otaless/shop-service.d.ts +111 -0
- package/dist/otaless/shop-service.d.ts.map +1 -0
- package/dist/otaless/shop-service.js +195 -0
- package/dist/otaless/shop-service.js.map +1 -0
- package/dist/otaless/shop.d.ts +169 -0
- package/dist/otaless/shop.d.ts.map +1 -0
- package/dist/otaless/shop.js +793 -0
- package/dist/otaless/shop.js.map +1 -0
- package/dist/otaless/wallet.d.ts +160 -0
- package/dist/otaless/wallet.d.ts.map +1 -0
- package/dist/otaless/wallet.js +650 -0
- package/dist/otaless/wallet.js.map +1 -0
- package/dist/server.d.ts +14 -3
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +89 -16
- package/dist/server.js.map +1 -1
- package/dist/surface.d.ts +7 -0
- package/dist/surface.d.ts.map +1 -1
- package/dist/surface.js +15 -1
- package/dist/surface.js.map +1 -1
- package/dist/tools.d.ts +223 -99
- package/dist/tools.d.ts.map +1 -1
- package/dist/tools.js +484 -75
- package/dist/tools.js.map +1 -1
- package/package.json +1 -1
package/dist/account/index.js
CHANGED
|
@@ -2,13 +2,17 @@ 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';
|
|
14
|
+
import { WALLET_CSS, addCardPage, confirmPage, confirmWords, noteOf, walletBlocks, } from './wallet-pages.js';
|
|
15
|
+
import { centsOfUsd, limitOf, makeWalletPart, usd as usdOfCents, } from './wallet.js';
|
|
12
16
|
// THE ACCOUNT: signing in to the deployment's own account - for Otaless, the hotel
|
|
13
17
|
// backend's own (`/ota/register`, `/ota/sign-in`, `/ota/sign-out`: 0.62.0, robin
|
|
14
18
|
// 11-10: 「ota 的登陆注册都是这个里面的…渠道和平台应该是一个接口」; the mall's
|
|
@@ -120,6 +124,17 @@ export const SIGN_IN_META_KEY = 'curless/account-sign-in';
|
|
|
120
124
|
/** …and beside a membership link's answer (0.58.0): the link and its group - no code (0.61.0). */
|
|
121
125
|
export const LINK_META_KEY = 'curless/account-link';
|
|
122
126
|
export const COOKIE = '__Host-hotel_account';
|
|
127
|
+
/**
|
|
128
|
+
* ⚠️ ONE COOKIE NAME PER DEPLOYMENT ON A SHARED ORIGIN (0.81.0, the Claude-only Otaless process
|
|
129
|
+
* at mcp.otaless.ai/claude beside the one at mcp.otaless.ai): a `__Host-` cookie is always
|
|
130
|
+
* `Path=/`, so two account pages on one host would each read the other's session id, find
|
|
131
|
+
* none, and sign the browser out of it. A deployment at the host's root keeps `COOKIE` as it
|
|
132
|
+
* was (its signed-in browsers stay signed in); one under a path gets that path in the name.
|
|
133
|
+
*/
|
|
134
|
+
export const cookieFor = (basePath) => {
|
|
135
|
+
const tail = basePath.replace(/^\/+|\/+$/g, '').replace(/[^A-Za-z0-9]+/g, '_');
|
|
136
|
+
return tail ? `${COOKIE}_${tail}` : COOKIE;
|
|
137
|
+
};
|
|
123
138
|
/** How many of what, and over how long - each refusal said as "too many requests". */
|
|
124
139
|
/** Accounts whose links are remembered (`account-links.json`): the one touched longest ago goes first. */
|
|
125
140
|
const MAX_REMEMBERED_ACCOUNTS = 20_000;
|
|
@@ -371,6 +386,17 @@ export const makeAccount = (opts) => {
|
|
|
371
386
|
...(opts.fetch ? { fetch: opts.fetch } : {}),
|
|
372
387
|
now,
|
|
373
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);
|
|
374
400
|
const log = opts.log ?? ((l) => console.log(l));
|
|
375
401
|
// The account's own membership - its level, points, growth points (0.73.0, `/ota/info`):
|
|
376
402
|
// by account, a few minutes, and within their limit by IP (info-cache.ts).
|
|
@@ -409,6 +435,7 @@ export const makeAccount = (opts) => {
|
|
|
409
435
|
const publicUrl = opts.publicUrl.replace(/\/+$/, '');
|
|
410
436
|
const origin = new URL(publicUrl).origin;
|
|
411
437
|
const base = new URL(publicUrl).pathname.replace(/\/+$/, '');
|
|
438
|
+
const cookie = cookieFor(base);
|
|
412
439
|
const brandPage = {
|
|
413
440
|
brand: opts.brand,
|
|
414
441
|
base,
|
|
@@ -429,6 +456,16 @@ export const makeAccount = (opts) => {
|
|
|
429
456
|
// offered, drawn or said - the tools, the card and the pages are as 0.57.1.
|
|
430
457
|
const memberships = (opts.account.memberships ?? []).filter((m) => typeof m?.code === 'string' && /^[a-z0-9_-]{1,32}$/i.test(m.code));
|
|
431
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');
|
|
432
469
|
const groupOf = (code) => typeof code === 'string'
|
|
433
470
|
? memberships.find((m) => m.code.toLowerCase() === code.trim().toLowerCase())
|
|
434
471
|
: undefined;
|
|
@@ -466,6 +503,9 @@ export const makeAccount = (opts) => {
|
|
|
466
503
|
const TERMS_MS_MAX = 10 * 60_000;
|
|
467
504
|
const termsRequests = createSignIns({ now, ttlMs: TERMS_MS_MAX, perKey: 10 });
|
|
468
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);
|
|
469
509
|
const remembered = new Map();
|
|
470
510
|
const clip = (v, n) => typeof v === 'string' && v.trim() ? v.trim().slice(0, n) : undefined;
|
|
471
511
|
/**
|
|
@@ -651,11 +691,11 @@ export const makeAccount = (opts) => {
|
|
|
651
691
|
* ⚠️ NEVER A REASON TO KEEP OUR LINK (0.79.1): the caller has forgotten it already; false says
|
|
652
692
|
* the group may still hold the old session, for the guest to be told.
|
|
653
693
|
*/
|
|
654
|
-
const endAtBackend = (code, input) =>
|
|
694
|
+
const endAtBackend = (code, input) => otaOf(code)
|
|
655
695
|
.signOut({ group: code, ...input })
|
|
656
696
|
.then(() => true)
|
|
657
697
|
.catch((e) => {
|
|
658
|
-
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}`);
|
|
659
699
|
return false;
|
|
660
700
|
});
|
|
661
701
|
/**
|
|
@@ -722,12 +762,16 @@ export const makeAccount = (opts) => {
|
|
|
722
762
|
: {}),
|
|
723
763
|
signIn: m.signIn !== false,
|
|
724
764
|
join: m.join === true,
|
|
765
|
+
// 0.82.0: the shop account is worded as an account by the card and the page (`via: "addon"`).
|
|
766
|
+
...(m.via === 'addon' ? { kind: 'shop' } : {}),
|
|
725
767
|
};
|
|
726
768
|
});
|
|
727
769
|
const membershipsSaid = (s, noCards) => {
|
|
728
770
|
if (!linking)
|
|
729
771
|
return '';
|
|
730
|
-
const
|
|
772
|
+
const all = membershipRows(s, false);
|
|
773
|
+
const rows = all.filter((r) => r.kind !== 'shop');
|
|
774
|
+
const shopRow = all.find((r) => r.kind === 'shop');
|
|
731
775
|
const linked = rows.filter((r) => r.linked);
|
|
732
776
|
const again = rows.filter((r) => r.relink);
|
|
733
777
|
const said = (code) => {
|
|
@@ -741,7 +785,9 @@ export const makeAccount = (opts) => {
|
|
|
741
785
|
: ''} Can be linked: ${rows
|
|
742
786
|
.filter((r) => !r.linked && !r.relink)
|
|
743
787
|
.map((r) => `${said(r.group)} (\`${r.group}\`)`)
|
|
744
|
-
.join(', ') || 'none more'} - ${names.link} gives the guest a one-time page for it
|
|
788
|
+
.join(', ') || 'none more'} - ${names.link} gives the guest a one-time page for it.${shopRow
|
|
789
|
+
? ` Shop account (${shopRow.name}, \`${shopRow.group}\`): ${shopRow.linked ? 'linked' : 'not linked'} - an account, not a membership${shopRow.linked ? '' : `; ${names.link} gives the guest a one-time page to link it`}.`
|
|
790
|
+
: ''}`;
|
|
745
791
|
};
|
|
746
792
|
// ── Signing in and out ───────────────────────────────────────────────────
|
|
747
793
|
/** Signed in now, for this conversation: whatever was there before is ended. */
|
|
@@ -777,6 +823,12 @@ export const makeAccount = (opts) => {
|
|
|
777
823
|
* did not answer at all is not asked again. Never throws; nothing waits for it.
|
|
778
824
|
*/
|
|
779
825
|
const signOutAll = async (token, own, each = []) => {
|
|
826
|
+
// The shop's session is the shop's own: ended on its path, first, while the token is good.
|
|
827
|
+
await Promise.allSettled(each
|
|
828
|
+
.filter((l) => addonMember && l.group === addonMember.code)
|
|
829
|
+
.map((l) => addonOta
|
|
830
|
+
.signOut({ group: l.group, ...(l.session ? { session: l.session } : {}), auth: token })
|
|
831
|
+
.catch((e) => log(`[account] the shop's sign-out did not answer (${codeOf(e)})`))));
|
|
780
832
|
try {
|
|
781
833
|
await ota.signOut({ auth: token });
|
|
782
834
|
return;
|
|
@@ -788,7 +840,7 @@ export const makeAccount = (opts) => {
|
|
|
788
840
|
}
|
|
789
841
|
log(`[account] signing out every channel at once was refused (${codeOf(e)}): one at a time`);
|
|
790
842
|
}
|
|
791
|
-
await Promise.allSettled(each.map((l) =>
|
|
843
|
+
await Promise.allSettled(each.map((l) => otaOf(l.group)
|
|
792
844
|
.signOut({ group: l.group, ...(l.session ? { session: l.session } : {}), auth: token })
|
|
793
845
|
.catch((e) => log(`[account] a membership's sign-out did not answer (${codeOf(e)})`))));
|
|
794
846
|
// The platform's own sign-in (no channel) has no channel session of its own to end.
|
|
@@ -891,6 +943,206 @@ export const makeAccount = (opts) => {
|
|
|
891
943
|
* held to our own day (`MAX_SESSION_S`), and two idle hours (store.ts).
|
|
892
944
|
*/
|
|
893
945
|
const checked = (key) => store.get(key);
|
|
946
|
+
// ⚠️ THE CONVERSATION'S OWN SIGN-IN AT THAT GROUP (see `Account.bookingAuth`).
|
|
947
|
+
// `account`: their member_user id as the digits they sent (ota-member.ts
|
|
948
|
+
// `exactId`) - with none given, who `shownOf` says. ⚠️ THE TOKEN IS THE
|
|
949
|
+
// CONVERSATION'S ONE, the latest sign-in's (0.72.0); the `Mcp-Session-Id` is still
|
|
950
|
+
// the group's own sign-in's (whether a newer sign-in replaces it too is questions #77).
|
|
951
|
+
const bookingAuth = (key, group) => {
|
|
952
|
+
const s = store.get(key);
|
|
953
|
+
if (!s)
|
|
954
|
+
return undefined;
|
|
955
|
+
const code = group.trim().toLowerCase();
|
|
956
|
+
const account = s.platform.memberUserId || s.shown.id;
|
|
957
|
+
const l = linking ? liveLink(s, code) : undefined;
|
|
958
|
+
if (l)
|
|
959
|
+
return {
|
|
960
|
+
token: s.platform.access,
|
|
961
|
+
...(l.mcpSessionId ? { mcpSessionId: l.mcpSessionId } : {}),
|
|
962
|
+
account,
|
|
963
|
+
};
|
|
964
|
+
// ⚠️ THE ACCOUNT'S OWN SIGN-IN BOOKS EVERY GROUP (0.74.0, robin 11-17: 「登陆平台就好,酒店
|
|
965
|
+
// 预订不需要每次登陆」): no group is asked to be linked before it is booked - its token
|
|
966
|
+
// goes, and the backend finds the group's linked credentials itself (its document:
|
|
967
|
+
// 「memberToken 为空时从 Redis 渠道凭据包取绑定的 mcpToken」, questions #78). Where it
|
|
968
|
+
// says the group is not linked (its 4012 again after a handshake, or its own words),
|
|
969
|
+
// booking.ts asks for the link then. The `Mcp-Session-Id`: a live link's, the account's
|
|
970
|
+
// own where it signed in on that group's channel, else none - booking.ts makes one (16).
|
|
971
|
+
return {
|
|
972
|
+
token: s.platform.access,
|
|
973
|
+
...(s.platform.provider === code && s.platform.mcpSessionId
|
|
974
|
+
? { mcpSessionId: s.platform.mcpSessionId }
|
|
975
|
+
: {}),
|
|
976
|
+
account,
|
|
977
|
+
};
|
|
978
|
+
};
|
|
979
|
+
// ── The Otaless wallet (docs/otaless-hotels.md §17) ────────────────────────
|
|
980
|
+
// ⚠️ OFF UNLESS THE DEPLOYMENT PASSES ONE (`data.otaless.wallet`): with none, nothing below is
|
|
981
|
+
// offered, drawn or said - the tools, schemas, instructions and pages are as they were (the
|
|
982
|
+
// frozen listing, otaless-wallet-account-0810-freeze.test.ts). The credential is the account's
|
|
983
|
+
// own token (`bookingAuth`), never logged or returned.
|
|
984
|
+
const walletMeta = (code) => {
|
|
985
|
+
const m = groupOf(code);
|
|
986
|
+
const logo = opts.groupLogo?.(code);
|
|
987
|
+
return {
|
|
988
|
+
code,
|
|
989
|
+
name: m ? groupName(m) : code,
|
|
990
|
+
...(m?.names?.zh ? { names: { zh: m.names.zh } } : {}),
|
|
991
|
+
...(logo ? { logo } : {}),
|
|
992
|
+
};
|
|
993
|
+
};
|
|
994
|
+
// ⚠️ A WALLET GROUP IS A MEMBERSHIP GROUP: its wallet sits with that group's membership row and
|
|
995
|
+
// is there only while the row is linked - a wallet group the account cannot link is a mistake.
|
|
996
|
+
for (const g of opts.wallet?.groups ?? [])
|
|
997
|
+
if (!groupOf(g))
|
|
998
|
+
throw new Error(`account: wallet group "${g}" is not one of account.memberships - the wallet is shown with the group's membership, which must be linkable`);
|
|
999
|
+
const walletPart = opts.wallet
|
|
1000
|
+
? makeWalletPart({ wallet: opts.wallet, meta: walletMeta, now, log })
|
|
1001
|
+
: undefined;
|
|
1002
|
+
/** The account page's wallet block - the page the guest does everything on. */
|
|
1003
|
+
const walletUrl = (lang) => `${publicUrl}/account?lang=${lang}#wallet`;
|
|
1004
|
+
const walletCtx = (s, key, ip) => ({
|
|
1005
|
+
// The same rows the page and the card show: linked, and not one that needs linking again.
|
|
1006
|
+
linkedOf: (group) => {
|
|
1007
|
+
const code = groupOf(group)?.code;
|
|
1008
|
+
return !!code && membershipRows(s, false).some((r) => r.group === code && r.linked);
|
|
1009
|
+
},
|
|
1010
|
+
credOf: (group) => {
|
|
1011
|
+
const a = bookingAuth(key, group);
|
|
1012
|
+
return a
|
|
1013
|
+
? { token: a.token, ...(a.mcpSessionId ? { session: a.mcpSessionId } : {}) }
|
|
1014
|
+
: undefined;
|
|
1015
|
+
},
|
|
1016
|
+
account: s.platform.memberUserId || s.shown.id,
|
|
1017
|
+
key,
|
|
1018
|
+
who: { conversation: key, ...(ip ? { address: ip } : {}) },
|
|
1019
|
+
});
|
|
1020
|
+
const walletSaid = (c, noCards) => groupSaid({ code: c.group, name: c.name, ...(c.names ? { names: c.names } : {}) }, noCards);
|
|
1021
|
+
const walletWords = (cards, lang, noCards) => walletPart?.textOf(cards, {
|
|
1022
|
+
noCards,
|
|
1023
|
+
url: walletUrl(lang),
|
|
1024
|
+
...(linking ? { linkTool: names.link } : {}),
|
|
1025
|
+
said: (c) => walletSaid(c, noCards),
|
|
1026
|
+
}) ?? '';
|
|
1027
|
+
/** An answer with the wallets read now: the same facts in the structure (the card's, the model's) and in the words. */
|
|
1028
|
+
const withWallets = async (s, key, answer, lang, noCards, ip) => {
|
|
1029
|
+
if (!walletPart)
|
|
1030
|
+
return answer;
|
|
1031
|
+
const wallets = await walletPart.readAll(walletCtx(s, key, ip));
|
|
1032
|
+
return {
|
|
1033
|
+
...answer,
|
|
1034
|
+
text: `${answer.text}\n\n${walletWords(wallets, lang, noCards)}`,
|
|
1035
|
+
structured: { ...answer.structured, wallets, walletUrl: walletUrl(lang) },
|
|
1036
|
+
};
|
|
1037
|
+
};
|
|
1038
|
+
const RESULT_WORDS = {
|
|
1039
|
+
'not-offered': 'that group has no wallet here',
|
|
1040
|
+
'signed-out': 'the guest is not signed in',
|
|
1041
|
+
'not-linked': 'the group membership is not linked just now',
|
|
1042
|
+
busy: 'it is busy or limited just now - try again in a few minutes',
|
|
1043
|
+
unavailable: 'the wallet could not be reached just now',
|
|
1044
|
+
'bad-input': 'what was sent is not valid',
|
|
1045
|
+
'no-such-card': 'that card is not on the account now',
|
|
1046
|
+
declined: 'the group did not accept it',
|
|
1047
|
+
'nothing-to-renew': 'there is nothing to renew',
|
|
1048
|
+
'bad-link': 'the card page could not be made',
|
|
1049
|
+
used: 'that confirmation was already used with other values',
|
|
1050
|
+
};
|
|
1051
|
+
const resultWords = (r) => {
|
|
1052
|
+
const what = {
|
|
1053
|
+
'add-card': 'adding a card',
|
|
1054
|
+
authorize: 'the authorization',
|
|
1055
|
+
limits: 'the change of limits',
|
|
1056
|
+
renew: 'the renewal',
|
|
1057
|
+
'remove-card': 'removing the card',
|
|
1058
|
+
}[r.action];
|
|
1059
|
+
if (r.outcome === 'unknown')
|
|
1060
|
+
return `Not known whether ${what} went through - it was not sent again; the wallet below is as read now. Do not say it is done or that it failed.`;
|
|
1061
|
+
if (r.outcome === 'changed')
|
|
1062
|
+
return 'Nothing was done: the wallet changed since the confirm screen. The wallet below is as read now; the guest asks again from it.';
|
|
1063
|
+
if (r.outcome === 'refused')
|
|
1064
|
+
return `Nothing was done: ${RESULT_WORDS[r.reason ?? 'unavailable']}.`;
|
|
1065
|
+
if (r.action === 'add-card')
|
|
1066
|
+
return 'A one-time page to add a card is ready; the guest opens it from the card. The card number is typed only on that page.';
|
|
1067
|
+
if (r.action === 'remove-card')
|
|
1068
|
+
return `Done: the card was removed.${r.heldUsd && r.heldUsd !== '0.00' ? ` US$${r.heldUsd} of a booking's hold is still on the credit line.` : ''}${r.releasedUsd ? ` US$${r.releasedUsd} of unused credit was released.` : ''}${r.releasedUsd === undefined ? ' The backend gave no released amount; the wallet below is as read now.' : ''}`;
|
|
1069
|
+
return `Done: ${what} went through. An authorization is a credit line, not a deposit.`;
|
|
1070
|
+
};
|
|
1071
|
+
/** The card's wallet steps (`wallet_*`): only the card's own tool reaches here (server.ts refuses a client that draws no card). */
|
|
1072
|
+
const walletAction = async (args, call) => {
|
|
1073
|
+
const { key } = call;
|
|
1074
|
+
const lang = langOf(args.lang) ?? 'en';
|
|
1075
|
+
const s = checked(key);
|
|
1076
|
+
const action = {
|
|
1077
|
+
wallet_add_card: 'add-card',
|
|
1078
|
+
wallet_authorize: 'authorize',
|
|
1079
|
+
wallet_limits: 'limits',
|
|
1080
|
+
wallet_renew: 'renew',
|
|
1081
|
+
wallet_remove_card: 'remove-card',
|
|
1082
|
+
}[String(args.action)];
|
|
1083
|
+
const part = walletPart;
|
|
1084
|
+
if (!part || !action || !s) {
|
|
1085
|
+
const base = await handle(names.view, { ...args, action: 'view' }, call);
|
|
1086
|
+
const result = {
|
|
1087
|
+
action: action ?? 'add-card',
|
|
1088
|
+
outcome: 'refused',
|
|
1089
|
+
reason: s ? 'bad-input' : 'signed-out',
|
|
1090
|
+
};
|
|
1091
|
+
return { ...base, structured: { ...base.structured, walletResult: result } };
|
|
1092
|
+
}
|
|
1093
|
+
const text = (v, re) => (typeof v === 'string' && re.test(v) ? v : undefined);
|
|
1094
|
+
const group = text(args.walletGroup, /^[A-Za-z0-9_-]{1,32}$/) ??
|
|
1095
|
+
(part.groups.length === 1 ? part.groups[0] : undefined);
|
|
1096
|
+
const cardId = text(args.cardId, /^[A-Za-z0-9_-]{1,64}$/);
|
|
1097
|
+
const press = text(args.press, /^[A-Za-z0-9_-]{16,64}$/);
|
|
1098
|
+
const ctx = walletCtx(s, key, call.ip);
|
|
1099
|
+
const bad = { action, outcome: 'refused', reason: 'bad-input' };
|
|
1100
|
+
let result;
|
|
1101
|
+
if (!group)
|
|
1102
|
+
result = bad;
|
|
1103
|
+
else if (action === 'add-card')
|
|
1104
|
+
result = await part.addCard(ctx, { group, lang });
|
|
1105
|
+
else if (action === 'renew')
|
|
1106
|
+
result = cardId ? await part.renew(ctx, { group, cardId }) : bad;
|
|
1107
|
+
else if (action === 'remove-card')
|
|
1108
|
+
result = cardId && press ? await part.removeCard(ctx, { group, cardId, press }) : bad;
|
|
1109
|
+
else if (action === 'authorize') {
|
|
1110
|
+
const amountCents = centsOfUsd(args.amountUsd);
|
|
1111
|
+
result =
|
|
1112
|
+
cardId && press && amountCents !== undefined
|
|
1113
|
+
? await part.authorize(ctx, { group, cardId, amountCents, press })
|
|
1114
|
+
: bad;
|
|
1115
|
+
}
|
|
1116
|
+
else {
|
|
1117
|
+
const perTxn = limitOf(args.perTxnUsd);
|
|
1118
|
+
const perDay = limitOf(args.perDayUsd);
|
|
1119
|
+
// `'unknown'`: the screen showed no current limit (the backend does not give one).
|
|
1120
|
+
const seenOf = (v) => (v === 'unknown' ? 'unknown' : limitOf(v));
|
|
1121
|
+
const seenPerTxn = seenOf(args.seenPerTxnUsd);
|
|
1122
|
+
const seenPerDay = seenOf(args.seenPerDayUsd);
|
|
1123
|
+
result =
|
|
1124
|
+
press &&
|
|
1125
|
+
perTxn !== undefined &&
|
|
1126
|
+
perDay !== undefined &&
|
|
1127
|
+
seenPerTxn !== undefined &&
|
|
1128
|
+
seenPerDay !== undefined
|
|
1129
|
+
? await part.setLimits(ctx, { group, perTxn, perDay, seenPerTxn, seenPerDay, press })
|
|
1130
|
+
: bad;
|
|
1131
|
+
}
|
|
1132
|
+
log(`[account] ${tag(key)} wallet ${action}: ${result.outcome}${result.reason ? ` (${result.reason})` : ''}`);
|
|
1133
|
+
// ⚠️ ONE FRESH READ AFTER THE WRITE: what the guest sees is what the wallet says now.
|
|
1134
|
+
const wallets = await part.readAll(ctx);
|
|
1135
|
+
const base = signedInAnswer(s, '', false);
|
|
1136
|
+
return {
|
|
1137
|
+
text: `${resultWords(result)}\n\n${base.text}\n\n${walletWords(wallets, lang, false)}`,
|
|
1138
|
+
structured: {
|
|
1139
|
+
...base.structured,
|
|
1140
|
+
wallets,
|
|
1141
|
+
walletUrl: walletUrl(lang),
|
|
1142
|
+
walletResult: result,
|
|
1143
|
+
},
|
|
1144
|
+
};
|
|
1145
|
+
};
|
|
894
1146
|
// ── The tools ────────────────────────────────────────────────────────────
|
|
895
1147
|
const NO_PRICE = linking
|
|
896
1148
|
? `Being signed in to ${brand} itself changes no price or room shown here; a hotel group's membership linked to the account (${names.link}) asks that group for its prices as the member.`
|
|
@@ -968,10 +1220,13 @@ export const makeAccount = (opts) => {
|
|
|
968
1220
|
isError: true,
|
|
969
1221
|
};
|
|
970
1222
|
const g = groupSaid(m, noCards);
|
|
1223
|
+
// The shop's account (0.82.0, `via: "addon"`) is an account, not a hotel membership: said so.
|
|
1224
|
+
const shopAcct = !!addonMember && m.code === addonMember.code;
|
|
1225
|
+
const kind = shopAcct ? 'account' : 'membership';
|
|
971
1226
|
const s = checked(key);
|
|
972
1227
|
if (!s)
|
|
973
1228
|
return {
|
|
974
|
-
text: `Linking a ${g}
|
|
1229
|
+
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)}.`,
|
|
975
1230
|
structured: { view: 'account', brand, signedIn: false, code: 'not_signed_in' },
|
|
976
1231
|
};
|
|
977
1232
|
const mode = args.mode === 'unlink' ? 'unlink' : args.mode === 'join' ? 'up' : 'in';
|
|
@@ -991,18 +1246,18 @@ export const makeAccount = (opts) => {
|
|
|
991
1246
|
? { structured: { ...answer.structured, unlinkNote: 'group-session-may-remain' } }
|
|
992
1247
|
: {}),
|
|
993
1248
|
text: was
|
|
994
|
-
? `The ${g}
|
|
995
|
-
: `No ${g}
|
|
1249
|
+
? `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.` : ''}`
|
|
1250
|
+
: `No ${g} ${kind} was linked, so nothing changed.`,
|
|
996
1251
|
};
|
|
997
1252
|
}
|
|
998
1253
|
if (liveLink(s, m.code))
|
|
999
1254
|
return {
|
|
1000
1255
|
...signedInAnswer(s, '', noCards),
|
|
1001
|
-
text: `A ${g}
|
|
1256
|
+
text: `A ${g} ${kind} is already linked to this ${brand} account. To use another, unlink it first.`,
|
|
1002
1257
|
};
|
|
1003
1258
|
if ((mode === 'up' && m.join !== true) || (mode === 'in' && m.signIn === false))
|
|
1004
1259
|
return {
|
|
1005
|
-
text: `A ${g}
|
|
1260
|
+
text: `A ${g} ${kind} cannot be ${mode === 'up' ? 'made' : 'linked'} here.`,
|
|
1006
1261
|
structured: { view: 'error', brand, code: 'not_offered' },
|
|
1007
1262
|
isError: true,
|
|
1008
1263
|
};
|
|
@@ -1044,7 +1299,11 @@ export const makeAccount = (opts) => {
|
|
|
1044
1299
|
const expiresAt = new Date(made.expiresAt).toISOString();
|
|
1045
1300
|
log(`[account] a membership link for ${tag(key)}${noCards ? ' in words' : ''}`);
|
|
1046
1301
|
usage({ key, kind: 'member', step: 'link', group: m.code, signUp: mode === 'up' });
|
|
1047
|
-
const what = mode === 'up'
|
|
1302
|
+
const what = mode === 'up'
|
|
1303
|
+
? shopAcct
|
|
1304
|
+
? `sign up for ${g} and link the new account`
|
|
1305
|
+
: `join ${g} and link the new membership`
|
|
1306
|
+
: `link their ${g} ${kind}`;
|
|
1048
1307
|
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`;
|
|
1049
1308
|
// ⚠️ NO CODE (0.61.0) - see the top of this file: the page is the account's own browser's.
|
|
1050
1309
|
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.`;
|
|
@@ -1128,10 +1387,46 @@ export const makeAccount = (opts) => {
|
|
|
1128
1387
|
expiresAt: new Date(made.expiresAt).toISOString(),
|
|
1129
1388
|
};
|
|
1130
1389
|
};
|
|
1390
|
+
/** The one-time add-on confirm's link: counted against the conversation like a membership link. */
|
|
1391
|
+
const addonLink = (key, ref, lang) => {
|
|
1392
|
+
if (!opts.addons)
|
|
1393
|
+
return undefined;
|
|
1394
|
+
const s = store.get(key);
|
|
1395
|
+
if (!s)
|
|
1396
|
+
return undefined;
|
|
1397
|
+
const c = opts.addons.pending(key, ref);
|
|
1398
|
+
if (!c)
|
|
1399
|
+
return undefined;
|
|
1400
|
+
if (counters.links.count(`link:${key}`) >= ACCOUNT_LIMITS.linksPerConversation) {
|
|
1401
|
+
refusals.links++;
|
|
1402
|
+
return undefined;
|
|
1403
|
+
}
|
|
1404
|
+
const ends = Date.parse(c.until);
|
|
1405
|
+
if (!Number.isFinite(ends) || ends <= now())
|
|
1406
|
+
return undefined;
|
|
1407
|
+
const l = langOf(lang);
|
|
1408
|
+
const made = addonRequests.create({
|
|
1409
|
+
key,
|
|
1410
|
+
...(l ? { lang: l } : {}),
|
|
1411
|
+
words: true,
|
|
1412
|
+
addon: { ref, sid: s.sid },
|
|
1413
|
+
});
|
|
1414
|
+
if (!made)
|
|
1415
|
+
return undefined;
|
|
1416
|
+
counters.links.add(`link:${key}`);
|
|
1417
|
+
made.request.expires = Math.min(made.request.expires, ends);
|
|
1418
|
+
log(`[account] an add-on confirm link for ${tag(key)}`);
|
|
1419
|
+
return {
|
|
1420
|
+
url: `${publicUrl}/account?addon=${made.code}${l ? `&lang=${l}` : ''}`,
|
|
1421
|
+
expiresAt: new Date(made.request.expires).toISOString(),
|
|
1422
|
+
};
|
|
1423
|
+
};
|
|
1131
1424
|
const handle = async (name, args, call) => {
|
|
1132
1425
|
const { key, noCards } = call;
|
|
1133
1426
|
// The card's own: the same three, by `action`.
|
|
1134
1427
|
if (name === names.card) {
|
|
1428
|
+
if (walletPart && typeof args.action === 'string' && args.action.startsWith('wallet_'))
|
|
1429
|
+
return walletAction(args, { ...call, noCards: false, fromCard: true });
|
|
1135
1430
|
const act = args.action === 'sign_in'
|
|
1136
1431
|
? names.signIn
|
|
1137
1432
|
: args.action === 'sign_out'
|
|
@@ -1155,7 +1450,7 @@ export const makeAccount = (opts) => {
|
|
|
1155
1450
|
// when it is fresh, and nothing shown where `/ota/info` does not answer.
|
|
1156
1451
|
if (s) {
|
|
1157
1452
|
await infos.get(s.shown.id, s.platform.access);
|
|
1158
|
-
return signedInAnswer(s, '', noCards);
|
|
1453
|
+
return withWallets(s, key, signedInAnswer(s, '', noCards), langOf(args.lang) ?? 'en', !!noCards, call.ip);
|
|
1159
1454
|
}
|
|
1160
1455
|
const waiting = requests.openFor(key);
|
|
1161
1456
|
// ⚠️ THE ASSISTANT, WHERE A CARD IS DRAWN, IS NOT TOLD "NOBODY" (0.56.1,
|
|
@@ -1280,6 +1575,27 @@ export const makeAccount = (opts) => {
|
|
|
1280
1575
|
};
|
|
1281
1576
|
};
|
|
1282
1577
|
const STR = { type: 'string' };
|
|
1578
|
+
const WALLET_ACTIONS = [
|
|
1579
|
+
'wallet_add_card',
|
|
1580
|
+
'wallet_authorize',
|
|
1581
|
+
'wallet_limits',
|
|
1582
|
+
'wallet_renew',
|
|
1583
|
+
'wallet_remove_card',
|
|
1584
|
+
];
|
|
1585
|
+
/** The wallet groups as the descriptions and the words name them. */
|
|
1586
|
+
const walletNamesSaid = (walletPart?.groups ?? []).map((g) => walletMeta(g).name).join(', ');
|
|
1587
|
+
/** The card tool's wallet properties - only with the switch on (the frozen listing). */
|
|
1588
|
+
const walletProps = () => ({
|
|
1589
|
+
walletGroup: { type: 'string', enum: [...(walletPart?.groups ?? [])] },
|
|
1590
|
+
cardId: { type: 'string', pattern: '^[A-Za-z0-9_-]{1,64}$' },
|
|
1591
|
+
amountUsd: { type: 'string', pattern: '^[0-9]{1,4}(\\.[0-9]{1,2})?$' },
|
|
1592
|
+
perTxnUsd: { type: 'string', pattern: '^([0-9]{1,4}(\\.[0-9]{1,2})?|none)$' },
|
|
1593
|
+
perDayUsd: { type: 'string', pattern: '^([0-9]{1,4}(\\.[0-9]{1,2})?|none)$' },
|
|
1594
|
+
// `unknown`: the card showed no current limit (the backend does not give one) - not compared.
|
|
1595
|
+
seenPerTxnUsd: { type: 'string', pattern: '^([0-9]{1,4}(\\.[0-9]{1,2})?|none|unknown)$' },
|
|
1596
|
+
seenPerDayUsd: { type: 'string', pattern: '^([0-9]{1,4}(\\.[0-9]{1,2})?|none|unknown)$' },
|
|
1597
|
+
press: { type: 'string', pattern: '^[A-Za-z0-9_-]{16,64}$' },
|
|
1598
|
+
});
|
|
1283
1599
|
const tools = () => [
|
|
1284
1600
|
{
|
|
1285
1601
|
name: names.signIn,
|
|
@@ -1312,7 +1628,7 @@ export const makeAccount = (opts) => {
|
|
|
1312
1628
|
// That rule is the SERVER INSTRUCTIONS' (`instructions` below, both versions), not this
|
|
1313
1629
|
// description's (0.75.0, T1: OpenAI - a description says what a tool does, not how the
|
|
1314
1630
|
// model should use it).
|
|
1315
|
-
description: `Whether the guest is signed in to their ${brand} account in this conversation, and the name the account goes by (its nickname where it has one). Its contact details are not given: they are on ${brand}'s account page
|
|
1631
|
+
description: `Whether the guest is signed in to their ${brand} account in this conversation, and the name the account goes by (its nickname where it has one). Its contact details are not given: they are on ${brand}'s account page.${walletPart ? ` It also reads the guest's ${walletNamesSaid} wallet, read only: available, authorized, charged and held credit in US dollars, the cards on it (brand, last four digits, expiry), its limits and the latest transactions.` : ''}`,
|
|
1316
1632
|
annotations: {
|
|
1317
1633
|
title: `My ${brand} account`,
|
|
1318
1634
|
readOnlyHint: true,
|
|
@@ -1340,7 +1656,7 @@ export const makeAccount = (opts) => {
|
|
|
1340
1656
|
name: names.link,
|
|
1341
1657
|
// ⚠️ NOTHING ABOUT THE GUEST IS ASKED FOR HERE - the group's email and
|
|
1342
1658
|
// password are typed on our page, never in the chat.
|
|
1343
|
-
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.map((m) => `\`${m.code}\` (${groupName(m)})`).join(', ')}
|
|
1659
|
+
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.map((m) => `\`${m.code}\` (${groupName(m)})`).join(', ')}.${addonMember ? ` \`${addonMember.code}\` is the ${groupName(addonMember)} shop account, not a hotel group and not a membership: the same page signs it in, signs it up or unlinks it.` : ''}`,
|
|
1344
1660
|
annotations: {
|
|
1345
1661
|
title: 'Link a hotel membership',
|
|
1346
1662
|
readOnlyHint: false,
|
|
@@ -1376,7 +1692,7 @@ export const makeAccount = (opts) => {
|
|
|
1376
1692
|
{
|
|
1377
1693
|
name: names.card,
|
|
1378
1694
|
// The card's own (app-only, server.ts): never offered to the assistant.
|
|
1379
|
-
description: `The booking card's own way to sign in to the ${brand} account, see who is signed in, or sign out - for the conversation the card was drawn for. The same steps as ${names.signIn}, ${linking ? `${names.view}, ${names.signOut} and ${names.link}` : `${names.view} and ${names.signOut}`}, called by the card itself
|
|
1695
|
+
description: `The booking card's own way to sign in to the ${brand} account, see who is signed in, or sign out - for the conversation the card was drawn for. The same steps as ${names.signIn}, ${linking ? `${names.view}, ${names.signOut} and ${names.link}` : `${names.view} and ${names.signOut}`}, called by the card itself.${walletPart ? ` And the ${walletNamesSaid} wallet's steps, each pressed by the guest on the card: add a card, authorize an amount, change limits, renew, remove a card.` : ''}`,
|
|
1380
1696
|
annotations: {
|
|
1381
1697
|
title: `${brand} account (card)`,
|
|
1382
1698
|
readOnlyHint: false,
|
|
@@ -1390,12 +1706,16 @@ export const makeAccount = (opts) => {
|
|
|
1390
1706
|
properties: {
|
|
1391
1707
|
action: {
|
|
1392
1708
|
type: 'string',
|
|
1393
|
-
enum:
|
|
1394
|
-
|
|
1395
|
-
|
|
1709
|
+
enum: [
|
|
1710
|
+
...(linking
|
|
1711
|
+
? ['sign_in', 'view', 'sign_out', 'link', 'join', 'unlink']
|
|
1712
|
+
: ['sign_in', 'view', 'sign_out']),
|
|
1713
|
+
...(walletPart ? WALLET_ACTIONS : []),
|
|
1714
|
+
],
|
|
1396
1715
|
},
|
|
1397
1716
|
lang: { type: 'string', enum: ['zh', 'en'] },
|
|
1398
1717
|
...(linking ? { group: { type: 'string', enum: memberships.map((m) => m.code) } } : {}),
|
|
1718
|
+
...(walletPart ? walletProps() : {}),
|
|
1399
1719
|
},
|
|
1400
1720
|
required: ['action'],
|
|
1401
1721
|
},
|
|
@@ -1423,6 +1743,9 @@ export const makeAccount = (opts) => {
|
|
|
1423
1743
|
accountUrl: STR,
|
|
1424
1744
|
code: STR,
|
|
1425
1745
|
...(linking ? { memberships: { type: 'array' }, group: STR } : {}),
|
|
1746
|
+
...(walletPart
|
|
1747
|
+
? { wallets: { type: 'array' }, walletUrl: STR, walletResult: { type: 'object' } }
|
|
1748
|
+
: {}),
|
|
1426
1749
|
},
|
|
1427
1750
|
required: ['view'],
|
|
1428
1751
|
},
|
|
@@ -1474,6 +1797,7 @@ export const makeAccount = (opts) => {
|
|
|
1474
1797
|
account: { type: 'object' },
|
|
1475
1798
|
accountUrl: STR,
|
|
1476
1799
|
...(linking ? { memberships: { type: 'array' } } : {}),
|
|
1800
|
+
...(walletPart ? { wallets: { type: 'array' }, walletUrl: STR } : {}),
|
|
1477
1801
|
},
|
|
1478
1802
|
required: ['view'],
|
|
1479
1803
|
},
|
|
@@ -1491,10 +1815,14 @@ export const makeAccount = (opts) => {
|
|
|
1491
1815
|
const LINK_SAID = linking
|
|
1492
1816
|
? ` HOTEL MEMBERSHIPS: a guest signed in to ${brand} can link a hotel group's loyalty membership to the account - ${memberships.map(groupName).join(', ')} - and that group's prices here are then asked for as the member. ${names.link} gives a one-time page for it (or joins the group, or unlinks); the group's email and password are typed on that page, never in the chat - never ask for or accept them here, and never write one back. Say a price is a member rate only where the answer says so.`
|
|
1493
1817
|
: '';
|
|
1818
|
+
const WALLET_SAID = (noCards) => walletPart
|
|
1819
|
+
? ` ${walletNamesSaid.toUpperCase()} WALLET: the account view (${names.view}) also shows the guest's ${walletNamesSaid} wallet - a credit line in US dollars that the guest authorizes on their own bank card, not a deposit. Read it for them when they ask and say what it shows. Adding a card, authorizing an amount, changing limits, renewing and removing a card are done by the guest ${noCards ? 'on the account page whose link the answer gives' : 'on the card or on the account page'}, never by you for them: do not offer to do them, and never say that money was added - an authorization is not a deposit.`
|
|
1820
|
+
: '';
|
|
1494
1821
|
const instructions = (noCards) => (noCards
|
|
1495
1822
|
? `${brand} ACCOUNT: a guest who wants to sign in to their ${brand} account, or create one, is given a one-time page by ${names.signIn}: pass on its link and its code exactly, and say they sign in or create the account on that page. Never ask for, or accept, a password in the chat, nor the email or phone number to sign in or link a membership with; if the guest types one of them, never write it back, whole or in part - not even to say which one to change or not to use again: call it \"the password you typed\" - and tell them to use the page and, as it went into a chat, to choose another, without naming the old one. The name, email and phone number a booking asks for are the booking's own details, not the account's: ask for them in the chat, as that booking tool needs them. When they say they are done, ${names.view} - with the conversation's trip, as every call - shows who is signed in; use it only when they ask, never on your own and never beside a list of hotels or a search; ${names.signOut} signs them out.${linking ? '' : ' Being signed in changes no price here: say nothing of member rates.'}`
|
|
1496
1823
|
: `${brand} ACCOUNT: the card's Sign in opens ${brand}'s own page, where the guest signs in or creates an account; ${names.signIn} does the same when they ask in words. The card tells you when the guest signs in or out on it - take its word, and do not look again to check. Look at the account (${names.view}) only when the guest asks about it - never on your own, and never beside a list of hotels. Never ask for, or accept, a password in the chat, nor the email or phone number to sign in or link a membership with; if the guest types one of them, never write it back, whole or in part - not even to say which one to change or not to use again: call it \"the password you typed\" - and tell them to use the page and, as it went into a chat, to choose another, without naming the old one. The name, email and phone number a booking asks for are the booking's own details, not the account's: the guest fills them in on the card's booking form. ${names.signOut} signs them out.${linking ? '' : ' Being signed in changes no price here: say nothing of member rates.'}`) +
|
|
1497
|
-
LINK_SAID
|
|
1824
|
+
LINK_SAID +
|
|
1825
|
+
WALLET_SAID(noCards);
|
|
1498
1826
|
// ── The pages ────────────────────────────────────────────────────────────
|
|
1499
1827
|
const send = (c, status, html) => c.html(html, status, PAGE_HEADERS);
|
|
1500
1828
|
const langFor = (c, r, form) => langOf(c.req.query('lang')) ??
|
|
@@ -1515,13 +1843,13 @@ export const makeAccount = (opts) => {
|
|
|
1515
1843
|
const cookieOf = (c) => {
|
|
1516
1844
|
for (const part of String(c.req.header('cookie') ?? '').split(';')) {
|
|
1517
1845
|
const at = part.indexOf('=');
|
|
1518
|
-
if (at > 0 && part.slice(0, at).trim() ===
|
|
1846
|
+
if (at > 0 && part.slice(0, at).trim() === cookie)
|
|
1519
1847
|
return part.slice(at + 1).trim();
|
|
1520
1848
|
}
|
|
1521
1849
|
return null;
|
|
1522
1850
|
};
|
|
1523
|
-
const setCookie = (c, id) => c.header('Set-Cookie', `${
|
|
1524
|
-
const clearCookie = (c) => c.header('Set-Cookie', `${
|
|
1851
|
+
const setCookie = (c, id) => c.header('Set-Cookie', `${cookie}=${id}; Path=/; Max-Age=${WEB_IDLE_MS / 1000}; HttpOnly; Secure; SameSite=Strict`, { append: true });
|
|
1852
|
+
const clearCookie = (c) => c.header('Set-Cookie', `${cookie}=; Path=/; Max-Age=0; HttpOnly; Secure; SameSite=Strict`, {
|
|
1525
1853
|
append: true,
|
|
1526
1854
|
});
|
|
1527
1855
|
const statusOf = (state) => state === 'unknown'
|
|
@@ -1583,7 +1911,10 @@ export const makeAccount = (opts) => {
|
|
|
1583
1911
|
};
|
|
1584
1912
|
const ownerOf = (c, r) => {
|
|
1585
1913
|
const at = sessionOf(c);
|
|
1586
|
-
return at.ws &&
|
|
1914
|
+
return at.ws &&
|
|
1915
|
+
at.s &&
|
|
1916
|
+
at.ws.key === r.key &&
|
|
1917
|
+
at.s.sid === (r.link ?? r.terms ?? r.addon)?.sid
|
|
1587
1918
|
? { id: at.id, s: at.s }
|
|
1588
1919
|
: null;
|
|
1589
1920
|
};
|
|
@@ -1598,6 +1929,7 @@ export const makeAccount = (opts) => {
|
|
|
1598
1929
|
group: m ? groupIn(m, lang) : String(r.link?.group),
|
|
1599
1930
|
...(m && logoPath(m.code) ? { logo: logoPath(m.code) } : {}),
|
|
1600
1931
|
accountName: nameOf(s),
|
|
1932
|
+
...(m?.via === 'addon' ? { shop: true } : {}),
|
|
1601
1933
|
mode: mode === 'up' && m?.join === true ? 'up' : 'in',
|
|
1602
1934
|
...(error ? { error: say(lang, error, m ? groupIn(m, lang) : brand, brand) } : {}),
|
|
1603
1935
|
...(error && said ? { said } : {}),
|
|
@@ -1611,6 +1943,7 @@ export const makeAccount = (opts) => {
|
|
|
1611
1943
|
code,
|
|
1612
1944
|
csrf: linkCsrf(r),
|
|
1613
1945
|
group: m ? groupIn(m, lang) : String(r.link?.group),
|
|
1946
|
+
...(m?.via === 'addon' ? { shop: true } : {}),
|
|
1614
1947
|
...(m && logoPath(m.code) ? { logo: logoPath(m.code) } : {}),
|
|
1615
1948
|
...(error ? { error: say(lang, error, brand) } : {}),
|
|
1616
1949
|
...(error && said ? { said } : {}),
|
|
@@ -1779,7 +2112,7 @@ export const makeAccount = (opts) => {
|
|
|
1779
2112
|
let joinLabel;
|
|
1780
2113
|
if (up) {
|
|
1781
2114
|
try {
|
|
1782
|
-
({ memberNo, label: joinLabel } = await
|
|
2115
|
+
({ memberNo, label: joinLabel } = await otaOf(m.code).register({
|
|
1783
2116
|
group: m.code,
|
|
1784
2117
|
name: values.name ?? '',
|
|
1785
2118
|
email: values.email ?? '',
|
|
@@ -1802,7 +2135,7 @@ export const makeAccount = (opts) => {
|
|
|
1802
2135
|
let link;
|
|
1803
2136
|
let got;
|
|
1804
2137
|
try {
|
|
1805
|
-
got = await
|
|
2138
|
+
got = await otaOf(m.code).signIn({
|
|
1806
2139
|
group: m.code,
|
|
1807
2140
|
identity: (up ? values.email : values.identity) ?? '',
|
|
1808
2141
|
password,
|
|
@@ -1823,7 +2156,7 @@ export const makeAccount = (opts) => {
|
|
|
1823
2156
|
// ⚠️ 409 "This record already exists. Please reset and try again." (0.79.1, questions
|
|
1824
2157
|
// #99): the group still holds an old record of this link - not the password's fault.
|
|
1825
2158
|
if (recordExists(e)) {
|
|
1826
|
-
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`);
|
|
2159
|
+
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`);
|
|
1827
2160
|
return again('link_conflict');
|
|
1828
2161
|
}
|
|
1829
2162
|
const said = saidBy(e);
|
|
@@ -1838,7 +2171,7 @@ export const makeAccount = (opts) => {
|
|
|
1838
2171
|
const now2 = store.get(r.key);
|
|
1839
2172
|
if (!now2 || now2.sid !== r.link?.sid) {
|
|
1840
2173
|
linkRequests.reopen(r);
|
|
1841
|
-
|
|
2174
|
+
otaOf(m.code)
|
|
1842
2175
|
.signOut({
|
|
1843
2176
|
group: m.code,
|
|
1844
2177
|
...(link.session ? { session: link.session } : {}),
|
|
@@ -1904,6 +2237,7 @@ export const makeAccount = (opts) => {
|
|
|
1904
2237
|
return send(c, 200, linkedPage(brandPage, {
|
|
1905
2238
|
lang,
|
|
1906
2239
|
group: groupIn(m, lang),
|
|
2240
|
+
...(m.via === 'addon' ? { shop: true } : {}),
|
|
1907
2241
|
...(link.label ? { label: link.label } : {}),
|
|
1908
2242
|
}));
|
|
1909
2243
|
}
|
|
@@ -2570,11 +2904,338 @@ export const makeAccount = (opts) => {
|
|
|
2570
2904
|
account: !!id,
|
|
2571
2905
|
}));
|
|
2572
2906
|
});
|
|
2907
|
+
/**
|
|
2908
|
+
* The wallet's steps on the account page (`wallet_*` forms): this browser is the account's, the
|
|
2909
|
+
* origin and the CSRF token were checked by the caller. ⚠️ AUTHORIZE, LIMITS AND REMOVE ARE TWO
|
|
2910
|
+
* STEPS: the `wallet_review_*` post draws a confirm page from a FRESH read and makes a
|
|
2911
|
+
* one-time ticket for exactly what it shows (this web session's, ten minutes, one use);
|
|
2912
|
+
* only `wallet_confirm` with that ticket sends anything. A note on the way back is a short
|
|
2913
|
+
* code - no amount, no card digits in the URL.
|
|
2914
|
+
*/
|
|
2915
|
+
const walletPost = async (c, at, body, lang) => {
|
|
2916
|
+
const part = walletPart;
|
|
2917
|
+
if (!part)
|
|
2918
|
+
return send(c, 400, statePage(brandPage, lang, 'checked', plainHref('/account')));
|
|
2919
|
+
const act = formStr(body.action, 40);
|
|
2920
|
+
const group = formStr(body.group, 32);
|
|
2921
|
+
const ctx = walletCtx(at.s, at.ws.key, ipOf(c));
|
|
2922
|
+
const back = (code) => c.redirect(`${base}/account?lang=${lang}&wallet=${code}#wallet`, 303);
|
|
2923
|
+
const nameIn = (code) => {
|
|
2924
|
+
const meta = walletMeta(code);
|
|
2925
|
+
return lang === 'zh' && meta.names?.zh ? meta.names.zh : meta.name;
|
|
2926
|
+
};
|
|
2927
|
+
if (!part.offers(group))
|
|
2928
|
+
return send(c, 400, statePage(brandPage, lang, 'checked', plainHref('/account')));
|
|
2929
|
+
const owner = hashOf(at.id ?? '');
|
|
2930
|
+
const cardId = formStr(body.cardId, 64);
|
|
2931
|
+
const code = (r) => r.outcome === 'done'
|
|
2932
|
+
? 'done'
|
|
2933
|
+
: r.outcome === 'unknown'
|
|
2934
|
+
? 'unknown'
|
|
2935
|
+
: r.outcome === 'changed'
|
|
2936
|
+
? 'changed'
|
|
2937
|
+
: 'refused';
|
|
2938
|
+
if (act === 'wallet_add_card') {
|
|
2939
|
+
const r = await part.addCard(ctx, { group, lang });
|
|
2940
|
+
return send(c, 200, addCardPage(brandPage, lang, {
|
|
2941
|
+
...(r.link ? { url: r.link.url } : {}),
|
|
2942
|
+
minutes: 15,
|
|
2943
|
+
group: nameIn(group),
|
|
2944
|
+
}));
|
|
2945
|
+
}
|
|
2946
|
+
if (act === 'wallet_renew') {
|
|
2947
|
+
if (!cardId)
|
|
2948
|
+
return back('refused');
|
|
2949
|
+
return back(code(await part.renew(ctx, { group, cardId })));
|
|
2950
|
+
}
|
|
2951
|
+
// ── Step one: a fresh read, a confirm page, a ticket.
|
|
2952
|
+
if (act === 'wallet_review_authorize' ||
|
|
2953
|
+
act === 'wallet_review_limits' ||
|
|
2954
|
+
act === 'wallet_review_remove') {
|
|
2955
|
+
const fresh = await part.readGroup(ctx, group, 0);
|
|
2956
|
+
const v = fresh.view;
|
|
2957
|
+
if (!v)
|
|
2958
|
+
return back('refused');
|
|
2959
|
+
const confirm = (ticket, words) => ticket
|
|
2960
|
+
? send(c, 200, confirmPage({
|
|
2961
|
+
b: brandPage,
|
|
2962
|
+
lang,
|
|
2963
|
+
csrf: at.ws.csrf,
|
|
2964
|
+
ticket,
|
|
2965
|
+
group,
|
|
2966
|
+
...words,
|
|
2967
|
+
}))
|
|
2968
|
+
: send(c, 429, statePage(brandPage, lang, 'limited', plainHref('/account')));
|
|
2969
|
+
if (act === 'wallet_review_authorize') {
|
|
2970
|
+
const amountCents = centsOfUsd(formStr(body.amount, 12).trim());
|
|
2971
|
+
const card = v.cards.find((x) => x.id === cardId);
|
|
2972
|
+
if (amountCents === undefined || !card)
|
|
2973
|
+
return back('refused');
|
|
2974
|
+
return confirm(part.issue(owner, { kind: 'authorize', group, cardId, amountCents }), confirmWords.authorize(lang, {
|
|
2975
|
+
usd: usdOfCents(amountCents),
|
|
2976
|
+
brand: card.brand,
|
|
2977
|
+
last4: card.last4,
|
|
2978
|
+
group: nameIn(group),
|
|
2979
|
+
available: usdOfCents(v.credit.availableCents),
|
|
2980
|
+
authorized: usdOfCents(v.credit.authorizedCents),
|
|
2981
|
+
}));
|
|
2982
|
+
}
|
|
2983
|
+
if (act === 'wallet_review_limits') {
|
|
2984
|
+
const field = (x) => {
|
|
2985
|
+
const t = formStr(x, 12).trim();
|
|
2986
|
+
return t === '' ? null : limitOf(t);
|
|
2987
|
+
};
|
|
2988
|
+
const perTxnCents = field(body.perTxn);
|
|
2989
|
+
const perDayCents = field(body.perDay);
|
|
2990
|
+
if (perTxnCents === undefined || perDayCents === undefined)
|
|
2991
|
+
return back('refused');
|
|
2992
|
+
const shown = (n) => (n === null ? null : usdOfCents(n));
|
|
2993
|
+
return confirm(part.issue(owner, {
|
|
2994
|
+
kind: 'limits',
|
|
2995
|
+
group,
|
|
2996
|
+
perTxnCents,
|
|
2997
|
+
perDayCents,
|
|
2998
|
+
seenPerTxnCents: v.limits ? v.limits.perTxnCents : 'unknown',
|
|
2999
|
+
seenPerDayCents: v.limits ? v.limits.perDayCents : 'unknown',
|
|
3000
|
+
}), confirmWords.limits(lang, {
|
|
3001
|
+
group: nameIn(group),
|
|
3002
|
+
perTxn: shown(perTxnCents),
|
|
3003
|
+
perDay: shown(perDayCents),
|
|
3004
|
+
// ⚠️ absent = the page says the current limits cannot be read - never "no limit".
|
|
3005
|
+
...(v.limits
|
|
3006
|
+
? { nowTxn: shown(v.limits.perTxnCents), nowDay: shown(v.limits.perDayCents) }
|
|
3007
|
+
: {}),
|
|
3008
|
+
}));
|
|
3009
|
+
}
|
|
3010
|
+
const card = v.cards.find((x) => x.id === cardId);
|
|
3011
|
+
if (!card)
|
|
3012
|
+
return back('refused');
|
|
3013
|
+
return confirm(part.issue(owner, { kind: 'remove', group, cardId }), confirmWords.remove(lang, {
|
|
3014
|
+
brand: card.brand,
|
|
3015
|
+
last4: card.last4,
|
|
3016
|
+
group: nameIn(group),
|
|
3017
|
+
held: usdOfCents(v.credit.heldCents),
|
|
3018
|
+
}));
|
|
3019
|
+
}
|
|
3020
|
+
// ── Step two: the ticket is taken (used) before anything is sent.
|
|
3021
|
+
if (act === 'wallet_confirm') {
|
|
3022
|
+
const ticketCode = formStr(body.ticket, 64);
|
|
3023
|
+
const t = part.take(owner, ticketCode);
|
|
3024
|
+
if (!t)
|
|
3025
|
+
return back('expired');
|
|
3026
|
+
// The ticket's own group, whatever the form says.
|
|
3027
|
+
const press = ticketCode;
|
|
3028
|
+
const r = t.kind === 'authorize'
|
|
3029
|
+
? await part.authorize(ctx, {
|
|
3030
|
+
group: t.group,
|
|
3031
|
+
cardId: t.cardId,
|
|
3032
|
+
amountCents: t.amountCents,
|
|
3033
|
+
press,
|
|
3034
|
+
})
|
|
3035
|
+
: t.kind === 'limits'
|
|
3036
|
+
? await part.setLimits(ctx, {
|
|
3037
|
+
group: t.group,
|
|
3038
|
+
perTxn: t.perTxnCents,
|
|
3039
|
+
perDay: t.perDayCents,
|
|
3040
|
+
seenPerTxn: t.seenPerTxnCents,
|
|
3041
|
+
seenPerDay: t.seenPerDayCents,
|
|
3042
|
+
press,
|
|
3043
|
+
})
|
|
3044
|
+
: await part.removeCard(ctx, { group: t.group, cardId: t.cardId, press });
|
|
3045
|
+
log(`[account] ${tag(at.ws.key)} wallet ${r.action} on the account page: ${r.outcome}${r.reason ? ` (${r.reason})` : ''}`);
|
|
3046
|
+
return back(code(r));
|
|
3047
|
+
}
|
|
3048
|
+
return send(c, 400, statePage(brandPage, lang, 'checked', plainHref('/account')));
|
|
3049
|
+
};
|
|
3050
|
+
// ── An add-on's confirm, on its own page (0.82.0) ──────────────────────────────────────────
|
|
3051
|
+
// ⚠️ ON THE EXISTING PATH `/account`, TOLD APART BY ?addon= (Caddy passes fixed paths only).
|
|
3052
|
+
// Guarded as the terms page is: only the browser holding THIS account's sign-in opens it
|
|
3053
|
+
// (`ownerOf`), else the same account signs in again here; a POST comes from our page (Origin)
|
|
3054
|
+
// with the request's own token; one POST at a time (`begin`); used once - pressing confirm OR
|
|
3055
|
+
// leaving ends it. The press is the only thing that can send: `opts.addons.confirm` takes the
|
|
3056
|
+
// prepared confirm (one use), re-reads, and sends at most once. NOTHING OF THE ADD-ON, THE
|
|
3057
|
+
// BOOKING OR THE GUEST IS LOGGED.
|
|
3058
|
+
const addonHref = (code) => (l) => `${base}/account?addon=${encodeURIComponent(code)}&lang=${l}`;
|
|
3059
|
+
const addonState = (r) => {
|
|
3060
|
+
const st = addonRequests.state(r, false);
|
|
3061
|
+
if (st !== 'open')
|
|
3062
|
+
return st;
|
|
3063
|
+
return store.get(r.key)?.sid === r.addon?.sid ? 'open' : 'expired';
|
|
3064
|
+
};
|
|
3065
|
+
// What a pressed confirm came to, by its link (live walkthrough 11-23: a second press while the
|
|
3066
|
+
// first was at the backend left the guest on "Working on it" - the outcome, and a payment link,
|
|
3067
|
+
// went to the first request's page, which the browser had dropped). The pending page looks
|
|
3068
|
+
// again every 2 s at the link itself; once done, the SAME account's browser (`ownerOf`) is shown
|
|
3069
|
+
// the outcome there. Kept as long as the used link is (requests.ts: 30 minutes), in memory only.
|
|
3070
|
+
const addonDone = new WeakMap();
|
|
3071
|
+
const addonNotOpen = (c, code, state, lang, r) => {
|
|
3072
|
+
const done = state === 'used' && r ? addonDone.get(r) : undefined;
|
|
3073
|
+
if (done && r && ownerOf(c, r))
|
|
3074
|
+
return send(c, 200, addonDonePage(brandPage, lang, code, done, true));
|
|
3075
|
+
return send(c, state === 'pending' ? 202 : state === 'tries' ? 429 : statusOf(state), addonStatePage(brandPage, lang, state === 'used'
|
|
3076
|
+
? 'used'
|
|
3077
|
+
: state === 'pending'
|
|
3078
|
+
? 'pending'
|
|
3079
|
+
: state === 'unknown'
|
|
3080
|
+
? 'unknown'
|
|
3081
|
+
: 'expired', addonHref(code), state === 'pending' ? addonHref(code)(lang) : undefined));
|
|
3082
|
+
};
|
|
3083
|
+
const addonReauth = (c, code, r, lang, error, said) => send(c, 200, linkReauthPage(brandPage, {
|
|
3084
|
+
lang,
|
|
3085
|
+
code,
|
|
3086
|
+
csrf: addonCsrf(r),
|
|
3087
|
+
group: brand,
|
|
3088
|
+
addon: true,
|
|
3089
|
+
...(error ? { error: say(lang, error, brand) } : {}),
|
|
3090
|
+
...(error && said ? { said } : {}),
|
|
3091
|
+
}));
|
|
3092
|
+
const addonGet = (c, code) => {
|
|
3093
|
+
const r = addonRequests.find(code);
|
|
3094
|
+
const lang = langFor(c, r);
|
|
3095
|
+
if (over(c, 'pages', ipOf(c), ACCOUNT_LIMITS.pagesPerIp))
|
|
3096
|
+
return send(c, 429, statePage(brandPage, lang, 'limited', plainHref('/account')));
|
|
3097
|
+
if (!r?.addon || !opts.addons)
|
|
3098
|
+
return addonNotOpen(c, code, 'unknown', lang);
|
|
3099
|
+
const state = addonState(r);
|
|
3100
|
+
if (state !== 'open')
|
|
3101
|
+
return addonNotOpen(c, code, state, lang, r);
|
|
3102
|
+
const owner = ownerOf(c, r);
|
|
3103
|
+
if (!owner)
|
|
3104
|
+
return addonReauth(c, code, r, lang);
|
|
3105
|
+
if (owner.id)
|
|
3106
|
+
setCookie(c, owner.id);
|
|
3107
|
+
const conf = opts.addons.pending(r.key, r.addon.ref);
|
|
3108
|
+
if (!conf)
|
|
3109
|
+
return send(c, 410, addonStatePage(brandPage, lang, 'gone', addonHref(code)));
|
|
3110
|
+
return send(c, 200, addonPage(brandPage, { lang, code, csrf: addonCsrf(r), confirm: conf }));
|
|
3111
|
+
};
|
|
3112
|
+
const addonPost = async (c, body, code, lang) => {
|
|
3113
|
+
const r = addonRequests.find(code);
|
|
3114
|
+
if (!r?.addon || !opts.addons)
|
|
3115
|
+
return addonNotOpen(c, code, 'unknown', lang);
|
|
3116
|
+
const state = addonState(r);
|
|
3117
|
+
if (state !== 'open')
|
|
3118
|
+
return addonNotOpen(c, code, state, lang, r);
|
|
3119
|
+
if (!same(body.csrf, addonCsrf(r))) {
|
|
3120
|
+
refusals.csrf++;
|
|
3121
|
+
return send(c, 403, statePage(brandPage, lang, 'checked', addonHref(code)));
|
|
3122
|
+
}
|
|
3123
|
+
if (!addonRequests.tried(r)) {
|
|
3124
|
+
log(`[account] an add-on link for ${tag(r.key)} refused after too many tries`);
|
|
3125
|
+
return send(c, 429, statePage(brandPage, lang, 'tries', addonHref(code)));
|
|
3126
|
+
}
|
|
3127
|
+
const s = store.get(r.key);
|
|
3128
|
+
if (!s || s.sid !== r.addon.sid)
|
|
3129
|
+
return addonNotOpen(c, code, 'expired', lang);
|
|
3130
|
+
// The account's own sign-in, again: it proves the browser is that account's.
|
|
3131
|
+
if (body.form === 'reauth') {
|
|
3132
|
+
const account = formStr(body.account, LIMITS.account).trim();
|
|
3133
|
+
const password = formStr(body.password, LIMITS.password);
|
|
3134
|
+
if (!account || !password)
|
|
3135
|
+
return addonReauth(c, code, r, lang, 'missing_in_email');
|
|
3136
|
+
if (notAnEmail(account))
|
|
3137
|
+
return addonReauth(c, code, r, lang, 'email_only');
|
|
3138
|
+
const named = `a:${account.toLowerCase()}`;
|
|
3139
|
+
if (nameFailures.shut(named, ACCOUNT_LIMITS.perName)) {
|
|
3140
|
+
refusals.names++;
|
|
3141
|
+
return addonReauth(c, code, r, lang, 'too_many');
|
|
3142
|
+
}
|
|
3143
|
+
if (over(c, 'all', 'in', ACCOUNT_LIMITS.signInsPerMinute))
|
|
3144
|
+
return send(c, 429, statePage(brandPage, lang, 'limited', addonHref(code)));
|
|
3145
|
+
if (!addonRequests.begin(r))
|
|
3146
|
+
return addonNotOpen(c, code, 'pending', lang);
|
|
3147
|
+
if (!nameFailures.enter(named, ACCOUNT_LIMITS.perName)) {
|
|
3148
|
+
addonRequests.reopen(r);
|
|
3149
|
+
refusals.names++;
|
|
3150
|
+
return addonReauth(c, code, r, lang, 'too_many');
|
|
3151
|
+
}
|
|
3152
|
+
let proved = null;
|
|
3153
|
+
let outcome = 'unknown';
|
|
3154
|
+
try {
|
|
3155
|
+
proved = await platformSignIn(tag(r.key), account, password, lang);
|
|
3156
|
+
outcome = 'ok';
|
|
3157
|
+
}
|
|
3158
|
+
catch (e) {
|
|
3159
|
+
addonRequests.reopen(r);
|
|
3160
|
+
outcome = notThere(e) ? 'unknown' : 'failed';
|
|
3161
|
+
logRefused(`[account] a re-sign-in for an add-on link of ${tag(r.key)} refused (${codeOf(e)})`, e);
|
|
3162
|
+
const said = saidBy(e);
|
|
3163
|
+
return said
|
|
3164
|
+
? addonReauth(c, code, r, lang, 'sign_in_refused', said)
|
|
3165
|
+
: addonReauth(c, code, r, lang, notThere(e) ? 'busy' : wrong(e) ? signInFailed : 'sign_in_unconfirmed');
|
|
3166
|
+
}
|
|
3167
|
+
finally {
|
|
3168
|
+
nameFailures.leave(named, outcome);
|
|
3169
|
+
}
|
|
3170
|
+
addonRequests.reopen(r);
|
|
3171
|
+
const still = store.get(r.key);
|
|
3172
|
+
const sameTok = (p, q) => p.access === q.access || (!!p.mcpToken && p.mcpToken === q.mcpToken);
|
|
3173
|
+
const who = shownOf(proved.session, proved.profile, account);
|
|
3174
|
+
if (!still || still.sid !== r.addon.sid) {
|
|
3175
|
+
if (!still || !sameTok(proved.session, still.platform))
|
|
3176
|
+
void endSession(proved.session);
|
|
3177
|
+
return addonNotOpen(c, code, 'expired', lang);
|
|
3178
|
+
}
|
|
3179
|
+
if (who.id !== still.shown.id) {
|
|
3180
|
+
if (!sameTok(proved.session, still.platform))
|
|
3181
|
+
void endSession(proved.session);
|
|
3182
|
+
log(`[account] an add-on link of ${tag(r.key)} opened by another account: refused`);
|
|
3183
|
+
return addonReauth(c, code, r, lang, 'reauth_other');
|
|
3184
|
+
}
|
|
3185
|
+
still.platform = proved.session;
|
|
3186
|
+
const id = web.open(r.key, still.sid);
|
|
3187
|
+
if (id)
|
|
3188
|
+
setCookie(c, id);
|
|
3189
|
+
const conf = opts.addons.pending(r.key, r.addon.ref);
|
|
3190
|
+
if (!conf)
|
|
3191
|
+
return send(c, 410, addonStatePage(brandPage, lang, 'gone', addonHref(code)));
|
|
3192
|
+
return send(c, 200, addonPage(brandPage, { lang, code, csrf: addonCsrf(r), confirm: conf }));
|
|
3193
|
+
}
|
|
3194
|
+
const owner = ownerOf(c, r);
|
|
3195
|
+
if (!owner)
|
|
3196
|
+
return addonReauth(c, code, r, lang);
|
|
3197
|
+
const action = body.action;
|
|
3198
|
+
if (action !== 'confirm' && action !== 'discard')
|
|
3199
|
+
return send(c, 400, statePage(brandPage, lang, 'checked', addonHref(code)));
|
|
3200
|
+
if (!addonRequests.begin(r))
|
|
3201
|
+
return addonNotOpen(c, code, 'pending', lang);
|
|
3202
|
+
const ref = r.addon.ref;
|
|
3203
|
+
if (action === 'discard') {
|
|
3204
|
+
opts.addons.discard(r.key, ref);
|
|
3205
|
+
r.state = 'done';
|
|
3206
|
+
r.doneAt = now();
|
|
3207
|
+
log(`[account] add-on confirm left k=${tag(r.key)}`);
|
|
3208
|
+
return send(c, 200, addonStatePage(brandPage, lang, 'gone', addonHref(code)));
|
|
3209
|
+
}
|
|
3210
|
+
// ⚠️ CONFIRM: ONE USE, WHATEVER COMES BACK - the prepared confirm is taken before anything is
|
|
3211
|
+
// sent, and so is this link.
|
|
3212
|
+
let done;
|
|
3213
|
+
try {
|
|
3214
|
+
done = await opts.addons.confirm(r.key, ref, lang);
|
|
3215
|
+
}
|
|
3216
|
+
catch {
|
|
3217
|
+
done = undefined;
|
|
3218
|
+
}
|
|
3219
|
+
r.state = 'done';
|
|
3220
|
+
r.doneAt = now();
|
|
3221
|
+
if (done)
|
|
3222
|
+
addonDone.set(r, done);
|
|
3223
|
+
if (!done) {
|
|
3224
|
+
log(`[account] add-on confirm k=${tag(r.key)} → gone`);
|
|
3225
|
+
return send(c, 410, addonStatePage(brandPage, lang, 'gone', addonHref(code)));
|
|
3226
|
+
}
|
|
3227
|
+
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' : ''}`);
|
|
3228
|
+
return send(c, 200, addonDonePage(brandPage, lang, code, done));
|
|
3229
|
+
};
|
|
2573
3230
|
app.get('/account', async (c) => {
|
|
2574
3231
|
// A group's booking terms, on this same path (0.63.0): told apart by the query.
|
|
2575
3232
|
const termsCode = c.req.query('terms');
|
|
2576
3233
|
if (termsCode !== undefined)
|
|
2577
3234
|
return termsGet(c, termsCode);
|
|
3235
|
+
// An add-on's confirm (0.82.0), likewise.
|
|
3236
|
+
const addonCode = c.req.query('addon');
|
|
3237
|
+
if (addonCode !== undefined)
|
|
3238
|
+
return addonGet(c, addonCode);
|
|
2578
3239
|
const lang = langFor(c);
|
|
2579
3240
|
if (over(c, 'pages', ipOf(c), ACCOUNT_LIMITS.pagesPerIp))
|
|
2580
3241
|
return send(c, 429, statePage(brandPage, lang, 'limited', plainHref('/account')));
|
|
@@ -2589,6 +3250,10 @@ export const makeAccount = (opts) => {
|
|
|
2589
3250
|
// The account's own level, points and growth points (0.73.0): asked for as the page
|
|
2590
3251
|
// opens - from what is known when fresh; nothing shown where it does not answer.
|
|
2591
3252
|
const info = await infos.get(at.s.shown.id, at.s.platform.access);
|
|
3253
|
+
// The wallet, read as the page opens (only with the switch on): the balance alone, fresh.
|
|
3254
|
+
const walletCards = walletPart
|
|
3255
|
+
? await walletPart.readAll(walletCtx(at.s, at.ws.key, ipOf(c)), 0)
|
|
3256
|
+
: undefined;
|
|
2592
3257
|
// Still signed in after the wait? Signed out meanwhile, the page says so.
|
|
2593
3258
|
if (store.get(at.ws.key)?.sid !== at.s.sid) {
|
|
2594
3259
|
clearCookie(c);
|
|
@@ -2612,6 +3277,23 @@ export const makeAccount = (opts) => {
|
|
|
2612
3277
|
: {}),
|
|
2613
3278
|
csrf: at.ws.csrf,
|
|
2614
3279
|
...(c.req.query('note') === 'session' ? { note: 'unlinkedStale' } : {}),
|
|
3280
|
+
...(walletCards
|
|
3281
|
+
? {
|
|
3282
|
+
wallet: {
|
|
3283
|
+
css: WALLET_CSS,
|
|
3284
|
+
subs: walletBlocks({
|
|
3285
|
+
b: brandPage,
|
|
3286
|
+
lang,
|
|
3287
|
+
csrf: at.ws.csrf,
|
|
3288
|
+
cards: walletCards,
|
|
3289
|
+
nameOf: (w) => (lang === 'zh' && w.names?.zh ? w.names.zh : w.name),
|
|
3290
|
+
...(noteOf(c.req.query('wallet'))
|
|
3291
|
+
? { note: noteOf(c.req.query('wallet')) }
|
|
3292
|
+
: {}),
|
|
3293
|
+
}),
|
|
3294
|
+
},
|
|
3295
|
+
}
|
|
3296
|
+
: {}),
|
|
2615
3297
|
// The card's rows, in the page's language and with each group's logo (0.61.0).
|
|
2616
3298
|
...(linking
|
|
2617
3299
|
? {
|
|
@@ -2628,6 +3310,7 @@ export const makeAccount = (opts) => {
|
|
|
2628
3310
|
...(row.numberMasked ? { numberMasked: row.numberMasked } : {}),
|
|
2629
3311
|
signIn: row.signIn,
|
|
2630
3312
|
join: row.join,
|
|
3313
|
+
...(row.kind === 'shop' ? { kind: 'shop' } : {}),
|
|
2631
3314
|
};
|
|
2632
3315
|
}),
|
|
2633
3316
|
}
|
|
@@ -2648,6 +3331,9 @@ export const makeAccount = (opts) => {
|
|
|
2648
3331
|
// A group's booking terms (0.63.0): the form's hidden `terms` field, handled first.
|
|
2649
3332
|
if (typeof body.terms === 'string')
|
|
2650
3333
|
return termsPost(c, body, formStr(body.terms, 64), lang);
|
|
3334
|
+
// An add-on's confirm (0.82.0): the form's hidden `addon` field.
|
|
3335
|
+
if (typeof body.addon === 'string')
|
|
3336
|
+
return addonPost(c, body, formStr(body.addon, 64), lang);
|
|
2651
3337
|
const at = sessionOf(c);
|
|
2652
3338
|
if (!at.ws || !at.s) {
|
|
2653
3339
|
if (at.id)
|
|
@@ -2658,6 +3344,9 @@ export const makeAccount = (opts) => {
|
|
|
2658
3344
|
refusals.csrf++;
|
|
2659
3345
|
return send(c, 403, statePage(brandPage, lang, 'checked', plainHref('/account')));
|
|
2660
3346
|
}
|
|
3347
|
+
// The wallet's steps (only with the switch on): after the origin and CSRF checks above.
|
|
3348
|
+
if (walletPart && typeof body.action === 'string' && body.action.startsWith('wallet_'))
|
|
3349
|
+
return walletPost(c, { id: at.id, ws: at.ws, s: at.s }, body, lang);
|
|
2661
3350
|
// A hotel group's membership, from the account page itself (0.58.0): this
|
|
2662
3351
|
// browser is the account's, so a link is made for it and opened here.
|
|
2663
3352
|
const m = linking ? groupOf(body.group) : undefined;
|
|
@@ -2866,40 +3555,9 @@ export const makeAccount = (opts) => {
|
|
|
2866
3555
|
if (inferLink(s, code))
|
|
2867
3556
|
log(`[account] ${tag(key)}: a booking at ${code} went through - remembered as linked (inferred from the booking)`);
|
|
2868
3557
|
},
|
|
2869
|
-
|
|
2870
|
-
// `account`: their member_user id as the digits they sent (ota-member.ts
|
|
2871
|
-
// `exactId`) - with none given, who `shownOf` says. ⚠️ THE TOKEN IS THE
|
|
2872
|
-
// CONVERSATION'S ONE, the latest sign-in's (0.72.0); the `Mcp-Session-Id` is still
|
|
2873
|
-
// the group's own sign-in's (whether a newer sign-in replaces it too is questions #77).
|
|
2874
|
-
bookingAuth: (key, group) => {
|
|
2875
|
-
const s = store.get(key);
|
|
2876
|
-
if (!s)
|
|
2877
|
-
return undefined;
|
|
2878
|
-
const code = group.trim().toLowerCase();
|
|
2879
|
-
const account = s.platform.memberUserId || s.shown.id;
|
|
2880
|
-
const l = linking ? liveLink(s, code) : undefined;
|
|
2881
|
-
if (l)
|
|
2882
|
-
return {
|
|
2883
|
-
token: s.platform.access,
|
|
2884
|
-
...(l.mcpSessionId ? { mcpSessionId: l.mcpSessionId } : {}),
|
|
2885
|
-
account,
|
|
2886
|
-
};
|
|
2887
|
-
// ⚠️ THE ACCOUNT'S OWN SIGN-IN BOOKS EVERY GROUP (0.74.0, robin 11-17: 「登陆平台就好,酒店
|
|
2888
|
-
// 预订不需要每次登陆」): no group is asked to be linked before it is booked - its token
|
|
2889
|
-
// goes, and the backend finds the group's linked credentials itself (its document:
|
|
2890
|
-
// 「memberToken 为空时从 Redis 渠道凭据包取绑定的 mcpToken」, questions #78). Where it
|
|
2891
|
-
// says the group is not linked (its 4012 again after a handshake, or its own words),
|
|
2892
|
-
// booking.ts asks for the link then. The `Mcp-Session-Id`: a live link's, the account's
|
|
2893
|
-
// own where it signed in on that group's channel, else none - booking.ts makes one (16).
|
|
2894
|
-
return {
|
|
2895
|
-
token: s.platform.access,
|
|
2896
|
-
...(s.platform.provider === code && s.platform.mcpSessionId
|
|
2897
|
-
? { mcpSessionId: s.platform.mcpSessionId }
|
|
2898
|
-
: {}),
|
|
2899
|
-
account,
|
|
2900
|
-
};
|
|
2901
|
-
},
|
|
3558
|
+
bookingAuth,
|
|
2902
3559
|
termsLink,
|
|
3560
|
+
addonLink,
|
|
2903
3561
|
instructions,
|
|
2904
3562
|
mount,
|
|
2905
3563
|
health: () => ({
|