@curless/hotel-storefront 0.81.0 → 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 +40 -0
- package/dist/account/index.d.ts.map +1 -1
- package/dist/account/index.js +292 -18
- 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 +24 -2
- package/dist/account/pages.d.ts.map +1 -1
- package/dist/account/pages.js +92 -33
- 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 +22 -7
- package/dist/otaless/make.js.map +1 -1
- package/dist/otaless/shop-answers.d.ts +15 -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
|
/**
|
|
@@ -736,12 +762,16 @@ export const makeAccount = (opts) => {
|
|
|
736
762
|
: {}),
|
|
737
763
|
signIn: m.signIn !== false,
|
|
738
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' } : {}),
|
|
739
767
|
};
|
|
740
768
|
});
|
|
741
769
|
const membershipsSaid = (s, noCards) => {
|
|
742
770
|
if (!linking)
|
|
743
771
|
return '';
|
|
744
|
-
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');
|
|
745
775
|
const linked = rows.filter((r) => r.linked);
|
|
746
776
|
const again = rows.filter((r) => r.relink);
|
|
747
777
|
const said = (code) => {
|
|
@@ -755,7 +785,9 @@ export const makeAccount = (opts) => {
|
|
|
755
785
|
: ''} Can be linked: ${rows
|
|
756
786
|
.filter((r) => !r.linked && !r.relink)
|
|
757
787
|
.map((r) => `${said(r.group)} (\`${r.group}\`)`)
|
|
758
|
-
.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
|
+
: ''}`;
|
|
759
791
|
};
|
|
760
792
|
// ── Signing in and out ───────────────────────────────────────────────────
|
|
761
793
|
/** Signed in now, for this conversation: whatever was there before is ended. */
|
|
@@ -791,6 +823,12 @@ export const makeAccount = (opts) => {
|
|
|
791
823
|
* did not answer at all is not asked again. Never throws; nothing waits for it.
|
|
792
824
|
*/
|
|
793
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)})`))));
|
|
794
832
|
try {
|
|
795
833
|
await ota.signOut({ auth: token });
|
|
796
834
|
return;
|
|
@@ -802,7 +840,7 @@ export const makeAccount = (opts) => {
|
|
|
802
840
|
}
|
|
803
841
|
log(`[account] signing out every channel at once was refused (${codeOf(e)}): one at a time`);
|
|
804
842
|
}
|
|
805
|
-
await Promise.allSettled(each.map((l) =>
|
|
843
|
+
await Promise.allSettled(each.map((l) => otaOf(l.group)
|
|
806
844
|
.signOut({ group: l.group, ...(l.session ? { session: l.session } : {}), auth: token })
|
|
807
845
|
.catch((e) => log(`[account] a membership's sign-out did not answer (${codeOf(e)})`))));
|
|
808
846
|
// The platform's own sign-in (no channel) has no channel session of its own to end.
|
|
@@ -1182,10 +1220,13 @@ export const makeAccount = (opts) => {
|
|
|
1182
1220
|
isError: true,
|
|
1183
1221
|
};
|
|
1184
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';
|
|
1185
1226
|
const s = checked(key);
|
|
1186
1227
|
if (!s)
|
|
1187
1228
|
return {
|
|
1188
|
-
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)}.`,
|
|
1189
1230
|
structured: { view: 'account', brand, signedIn: false, code: 'not_signed_in' },
|
|
1190
1231
|
};
|
|
1191
1232
|
const mode = args.mode === 'unlink' ? 'unlink' : args.mode === 'join' ? 'up' : 'in';
|
|
@@ -1205,18 +1246,18 @@ export const makeAccount = (opts) => {
|
|
|
1205
1246
|
? { structured: { ...answer.structured, unlinkNote: 'group-session-may-remain' } }
|
|
1206
1247
|
: {}),
|
|
1207
1248
|
text: was
|
|
1208
|
-
? `The ${g}
|
|
1209
|
-
: `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.`,
|
|
1210
1251
|
};
|
|
1211
1252
|
}
|
|
1212
1253
|
if (liveLink(s, m.code))
|
|
1213
1254
|
return {
|
|
1214
1255
|
...signedInAnswer(s, '', noCards),
|
|
1215
|
-
text: `A ${g}
|
|
1256
|
+
text: `A ${g} ${kind} is already linked to this ${brand} account. To use another, unlink it first.`,
|
|
1216
1257
|
};
|
|
1217
1258
|
if ((mode === 'up' && m.join !== true) || (mode === 'in' && m.signIn === false))
|
|
1218
1259
|
return {
|
|
1219
|
-
text: `A ${g}
|
|
1260
|
+
text: `A ${g} ${kind} cannot be ${mode === 'up' ? 'made' : 'linked'} here.`,
|
|
1220
1261
|
structured: { view: 'error', brand, code: 'not_offered' },
|
|
1221
1262
|
isError: true,
|
|
1222
1263
|
};
|
|
@@ -1258,7 +1299,11 @@ export const makeAccount = (opts) => {
|
|
|
1258
1299
|
const expiresAt = new Date(made.expiresAt).toISOString();
|
|
1259
1300
|
log(`[account] a membership link for ${tag(key)}${noCards ? ' in words' : ''}`);
|
|
1260
1301
|
usage({ key, kind: 'member', step: 'link', group: m.code, signUp: mode === 'up' });
|
|
1261
|
-
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}`;
|
|
1262
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`;
|
|
1263
1308
|
// ⚠️ NO CODE (0.61.0) - see the top of this file: the page is the account's own browser's.
|
|
1264
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.`;
|
|
@@ -1342,6 +1387,40 @@ export const makeAccount = (opts) => {
|
|
|
1342
1387
|
expiresAt: new Date(made.expiresAt).toISOString(),
|
|
1343
1388
|
};
|
|
1344
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
|
+
};
|
|
1345
1424
|
const handle = async (name, args, call) => {
|
|
1346
1425
|
const { key, noCards } = call;
|
|
1347
1426
|
// The card's own: the same three, by `action`.
|
|
@@ -1577,7 +1656,7 @@ export const makeAccount = (opts) => {
|
|
|
1577
1656
|
name: names.link,
|
|
1578
1657
|
// ⚠️ NOTHING ABOUT THE GUEST IS ASKED FOR HERE - the group's email and
|
|
1579
1658
|
// 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.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.` : ''}`,
|
|
1581
1660
|
annotations: {
|
|
1582
1661
|
title: 'Link a hotel membership',
|
|
1583
1662
|
readOnlyHint: false,
|
|
@@ -1832,7 +1911,10 @@ export const makeAccount = (opts) => {
|
|
|
1832
1911
|
};
|
|
1833
1912
|
const ownerOf = (c, r) => {
|
|
1834
1913
|
const at = sessionOf(c);
|
|
1835
|
-
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
|
|
1836
1918
|
? { id: at.id, s: at.s }
|
|
1837
1919
|
: null;
|
|
1838
1920
|
};
|
|
@@ -1847,6 +1929,7 @@ export const makeAccount = (opts) => {
|
|
|
1847
1929
|
group: m ? groupIn(m, lang) : String(r.link?.group),
|
|
1848
1930
|
...(m && logoPath(m.code) ? { logo: logoPath(m.code) } : {}),
|
|
1849
1931
|
accountName: nameOf(s),
|
|
1932
|
+
...(m?.via === 'addon' ? { shop: true } : {}),
|
|
1850
1933
|
mode: mode === 'up' && m?.join === true ? 'up' : 'in',
|
|
1851
1934
|
...(error ? { error: say(lang, error, m ? groupIn(m, lang) : brand, brand) } : {}),
|
|
1852
1935
|
...(error && said ? { said } : {}),
|
|
@@ -1860,6 +1943,7 @@ export const makeAccount = (opts) => {
|
|
|
1860
1943
|
code,
|
|
1861
1944
|
csrf: linkCsrf(r),
|
|
1862
1945
|
group: m ? groupIn(m, lang) : String(r.link?.group),
|
|
1946
|
+
...(m?.via === 'addon' ? { shop: true } : {}),
|
|
1863
1947
|
...(m && logoPath(m.code) ? { logo: logoPath(m.code) } : {}),
|
|
1864
1948
|
...(error ? { error: say(lang, error, brand) } : {}),
|
|
1865
1949
|
...(error && said ? { said } : {}),
|
|
@@ -2028,7 +2112,7 @@ export const makeAccount = (opts) => {
|
|
|
2028
2112
|
let joinLabel;
|
|
2029
2113
|
if (up) {
|
|
2030
2114
|
try {
|
|
2031
|
-
({ memberNo, label: joinLabel } = await
|
|
2115
|
+
({ memberNo, label: joinLabel } = await otaOf(m.code).register({
|
|
2032
2116
|
group: m.code,
|
|
2033
2117
|
name: values.name ?? '',
|
|
2034
2118
|
email: values.email ?? '',
|
|
@@ -2051,7 +2135,7 @@ export const makeAccount = (opts) => {
|
|
|
2051
2135
|
let link;
|
|
2052
2136
|
let got;
|
|
2053
2137
|
try {
|
|
2054
|
-
got = await
|
|
2138
|
+
got = await otaOf(m.code).signIn({
|
|
2055
2139
|
group: m.code,
|
|
2056
2140
|
identity: (up ? values.email : values.identity) ?? '',
|
|
2057
2141
|
password,
|
|
@@ -2072,7 +2156,7 @@ export const makeAccount = (opts) => {
|
|
|
2072
2156
|
// ⚠️ 409 "This record already exists. Please reset and try again." (0.79.1, questions
|
|
2073
2157
|
// #99): the group still holds an old record of this link - not the password's fault.
|
|
2074
2158
|
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`);
|
|
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`);
|
|
2076
2160
|
return again('link_conflict');
|
|
2077
2161
|
}
|
|
2078
2162
|
const said = saidBy(e);
|
|
@@ -2087,7 +2171,7 @@ export const makeAccount = (opts) => {
|
|
|
2087
2171
|
const now2 = store.get(r.key);
|
|
2088
2172
|
if (!now2 || now2.sid !== r.link?.sid) {
|
|
2089
2173
|
linkRequests.reopen(r);
|
|
2090
|
-
|
|
2174
|
+
otaOf(m.code)
|
|
2091
2175
|
.signOut({
|
|
2092
2176
|
group: m.code,
|
|
2093
2177
|
...(link.session ? { session: link.session } : {}),
|
|
@@ -2153,6 +2237,7 @@ export const makeAccount = (opts) => {
|
|
|
2153
2237
|
return send(c, 200, linkedPage(brandPage, {
|
|
2154
2238
|
lang,
|
|
2155
2239
|
group: groupIn(m, lang),
|
|
2240
|
+
...(m.via === 'addon' ? { shop: true } : {}),
|
|
2156
2241
|
...(link.label ? { label: link.label } : {}),
|
|
2157
2242
|
}));
|
|
2158
2243
|
}
|
|
@@ -2962,11 +3047,195 @@ export const makeAccount = (opts) => {
|
|
|
2962
3047
|
}
|
|
2963
3048
|
return send(c, 400, statePage(brandPage, lang, 'checked', plainHref('/account')));
|
|
2964
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
|
+
};
|
|
2965
3230
|
app.get('/account', async (c) => {
|
|
2966
3231
|
// A group's booking terms, on this same path (0.63.0): told apart by the query.
|
|
2967
3232
|
const termsCode = c.req.query('terms');
|
|
2968
3233
|
if (termsCode !== undefined)
|
|
2969
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);
|
|
2970
3239
|
const lang = langFor(c);
|
|
2971
3240
|
if (over(c, 'pages', ipOf(c), ACCOUNT_LIMITS.pagesPerIp))
|
|
2972
3241
|
return send(c, 429, statePage(brandPage, lang, 'limited', plainHref('/account')));
|
|
@@ -3041,6 +3310,7 @@ export const makeAccount = (opts) => {
|
|
|
3041
3310
|
...(row.numberMasked ? { numberMasked: row.numberMasked } : {}),
|
|
3042
3311
|
signIn: row.signIn,
|
|
3043
3312
|
join: row.join,
|
|
3313
|
+
...(row.kind === 'shop' ? { kind: 'shop' } : {}),
|
|
3044
3314
|
};
|
|
3045
3315
|
}),
|
|
3046
3316
|
}
|
|
@@ -3061,6 +3331,9 @@ export const makeAccount = (opts) => {
|
|
|
3061
3331
|
// A group's booking terms (0.63.0): the form's hidden `terms` field, handled first.
|
|
3062
3332
|
if (typeof body.terms === 'string')
|
|
3063
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);
|
|
3064
3337
|
const at = sessionOf(c);
|
|
3065
3338
|
if (!at.ws || !at.s) {
|
|
3066
3339
|
if (at.id)
|
|
@@ -3284,6 +3557,7 @@ export const makeAccount = (opts) => {
|
|
|
3284
3557
|
},
|
|
3285
3558
|
bookingAuth,
|
|
3286
3559
|
termsLink,
|
|
3560
|
+
addonLink,
|
|
3287
3561
|
instructions,
|
|
3288
3562
|
mount,
|
|
3289
3563
|
health: () => ({
|