@curless/hotel-storefront 0.62.0 → 0.63.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/account/fake-ota.d.ts +9 -0
- package/dist/account/fake-ota.d.ts.map +1 -1
- package/dist/account/fake-ota.js +7 -2
- package/dist/account/fake-ota.js.map +1 -1
- package/dist/account/index.d.ts +28 -0
- package/dist/account/index.d.ts.map +1 -1
- package/dist/account/index.js +402 -2
- package/dist/account/index.js.map +1 -1
- package/dist/account/pages.d.ts +99 -0
- package/dist/account/pages.d.ts.map +1 -1
- package/dist/account/pages.js +228 -4
- 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 +27 -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 +31 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +10 -0
- package/dist/config.js.map +1 -1
- package/dist/legal.d.ts.map +1 -1
- package/dist/legal.js +34 -22
- package/dist/legal.js.map +1 -1
- package/dist/otaless/backend.d.ts +37 -1
- package/dist/otaless/backend.d.ts.map +1 -1
- package/dist/otaless/backend.js +40 -17
- package/dist/otaless/backend.js.map +1 -1
- package/dist/otaless/booking.d.ts +86 -5
- package/dist/otaless/booking.d.ts.map +1 -1
- package/dist/otaless/booking.js +230 -49
- package/dist/otaless/booking.js.map +1 -1
- package/dist/otaless/client.d.ts +20 -0
- package/dist/otaless/client.d.ts.map +1 -1
- package/dist/otaless/client.js +20 -3
- package/dist/otaless/client.js.map +1 -1
- package/dist/otaless/fake.d.ts +7 -0
- package/dist/otaless/fake.d.ts.map +1 -1
- package/dist/otaless/fake.js +3 -0
- package/dist/otaless/fake.js.map +1 -1
- package/dist/otaless/make.d.ts.map +1 -1
- package/dist/otaless/make.js +42 -5
- package/dist/otaless/make.js.map +1 -1
- package/dist/server.d.ts +2 -2
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +115 -3
- package/dist/server.js.map +1 -1
- package/dist/surface.d.ts +6 -0
- package/dist/surface.d.ts.map +1 -1
- package/dist/surface.js +73 -23
- package/dist/surface.js.map +1 -1
- package/dist/tools.d.ts +251 -52
- package/dist/tools.d.ts.map +1 -1
- package/dist/tools.js +974 -225
- package/dist/tools.js.map +1 -1
- package/dist/types.d.ts +32 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/otaless/booking.js
CHANGED
|
@@ -28,9 +28,9 @@ import { CHANNEL_SESSION_EXPIRED, NOT_SIGNED_IN, OtalessBusy, OtalessError, REPE
|
|
|
28
28
|
// 4012 is kept by sign-in and group, in memory only. A 4012 is answered
|
|
29
29
|
// with one new handshake and one more try - never a loop.
|
|
30
30
|
//
|
|
31
|
-
// ⚠️ NOTHING HERE IS REACHED
|
|
32
|
-
//
|
|
33
|
-
//
|
|
31
|
+
// ⚠️ NOTHING HERE IS REACHED UNLESS THE DEPLOYMENT TURNS BOOKING ON
|
|
32
|
+
// (`data.otaless.booking`, 酒店平台 0.63.0; robin 11-10 「我们要跑通测试流程的」):
|
|
33
|
+
// read-only - the default - the tools that would call it are not offered.
|
|
34
34
|
/** How long terms sent back for agreement are kept for the guest to agree to (§12.1). */
|
|
35
35
|
export const TERMS_MS = 10 * 60_000;
|
|
36
36
|
/** How long a group's `Mcp-Session-Id` is kept unused (§12.3). */
|
|
@@ -54,7 +54,10 @@ const CHECKED_PER_LOOK = 5;
|
|
|
54
54
|
* no wildcard, no other port.
|
|
55
55
|
*/
|
|
56
56
|
export const DEFAULT_CHECKOUT_HOSTS = ['mcp.curless.ai', 'pay.discoverasr.com'];
|
|
57
|
+
/** How long a refund's preview can be sent back (总线程's review of 0.63.0, B). */
|
|
58
|
+
export const REFUND_PREVIEW_MS = 10 * 60_000;
|
|
57
59
|
const refusal = (code, message) => Object.assign(new Error(message), { code });
|
|
60
|
+
const signInRefusal = (code, message, groups) => Object.assign(new Error(message), { code, groups: [...groups] });
|
|
58
61
|
const num = (v) => {
|
|
59
62
|
const n = typeof v === 'string' && v.trim() ? Number(v) : v;
|
|
60
63
|
return typeof n === 'number' && Number.isFinite(n) ? n : undefined;
|
|
@@ -70,9 +73,46 @@ const moneyOf = (amount, currency) => {
|
|
|
70
73
|
return money(toMinor(a, c), c);
|
|
71
74
|
};
|
|
72
75
|
const same = (a, b) => !!a && !!b && a.currency === b.currency && a.minor === b.minor;
|
|
76
|
+
/**
|
|
77
|
+
* A path as its segments, the way a server reads it: empty segments (`//`)
|
|
78
|
+
* gone, `%2e` read as `.`, `.` and `..` resolved - or undefined for a segment
|
|
79
|
+
* holding an encoded or literal slash or backslash (`%2f`, `%5c`, `\`), which
|
|
80
|
+
* a server may read as more than one segment.
|
|
81
|
+
*/
|
|
82
|
+
export const pathSegments = (path) => {
|
|
83
|
+
const out = [];
|
|
84
|
+
for (const raw of path.split('/')) {
|
|
85
|
+
if (!raw)
|
|
86
|
+
continue;
|
|
87
|
+
if (/%2f|%5c/i.test(raw) || raw.includes('\\'))
|
|
88
|
+
return undefined;
|
|
89
|
+
const seg = raw.replace(/%2e/gi, '.');
|
|
90
|
+
if (seg === '.')
|
|
91
|
+
continue;
|
|
92
|
+
if (seg === '..') {
|
|
93
|
+
out.pop();
|
|
94
|
+
continue;
|
|
95
|
+
}
|
|
96
|
+
out.push(seg);
|
|
97
|
+
}
|
|
98
|
+
return out;
|
|
99
|
+
};
|
|
100
|
+
/** One `checkoutHosts` entry: a host, and - written `host/a/b/` - the path a page must be under. */
|
|
101
|
+
export const checkoutEntryOf = (entry) => {
|
|
102
|
+
const e = entry.trim();
|
|
103
|
+
const slash = e.indexOf('/');
|
|
104
|
+
const host = (slash < 0 ? e : e.slice(0, slash)).toLowerCase();
|
|
105
|
+
const under = slash < 0 ? [] : (pathSegments(e.slice(slash)) ?? ['\u0000']);
|
|
106
|
+
return { host, under };
|
|
107
|
+
};
|
|
73
108
|
/**
|
|
74
109
|
* Where a payment page may send the guest: `https:`, an exact host on the
|
|
75
|
-
* list, no other port, no user in it - or nothing (总线程 11-10).
|
|
110
|
+
* list, no other port, no user in it - or nothing (总线程 11-10). An entry
|
|
111
|
+
* written with a path (`mcp.curless.ai/pay/`) also holds it to that path, by
|
|
112
|
+
* whole segments, compared after the path is put the way a server reads it
|
|
113
|
+
* (`pathSegments`: no `..`, `%2e` or `//` slips past); an entry of a host alone
|
|
114
|
+
* takes any path on it (总线程's review of 0.63.0, 8). The page handed on is
|
|
115
|
+
* the one checked: its path as compared.
|
|
76
116
|
*/
|
|
77
117
|
export const payPageOf = (raw, hosts) => {
|
|
78
118
|
if (!raw)
|
|
@@ -87,8 +127,16 @@ export const payPageOf = (raw, hosts) => {
|
|
|
87
127
|
const host = u.hostname.toLowerCase();
|
|
88
128
|
if (u.protocol !== 'https:' || u.username || u.password || u.port)
|
|
89
129
|
return undefined;
|
|
90
|
-
|
|
130
|
+
const segs = pathSegments(u.pathname);
|
|
131
|
+
if (!segs)
|
|
91
132
|
return undefined;
|
|
133
|
+
const allowed = hosts.some((h) => {
|
|
134
|
+
const e = checkoutEntryOf(h);
|
|
135
|
+
return e.host === host && e.under.every((seg, i) => segs[i] === seg);
|
|
136
|
+
});
|
|
137
|
+
if (!allowed)
|
|
138
|
+
return undefined;
|
|
139
|
+
u.pathname = `/${segs.join('/')}${segs.length && u.pathname.endsWith('/') ? '/' : ''}`;
|
|
92
140
|
return { url: u.toString(), host };
|
|
93
141
|
};
|
|
94
142
|
/** The host of a URL for the log - never its path or query (they carry the payment token). */
|
|
@@ -109,6 +157,36 @@ const firstText = (o, keys) => {
|
|
|
109
157
|
}
|
|
110
158
|
return undefined;
|
|
111
159
|
};
|
|
160
|
+
/**
|
|
161
|
+
* The statuses a cancellation (9 `booking/cancel`, 14 `checkout/cancel`) is
|
|
162
|
+
* taken as DONE by - exactly these, case aside (总线程's review of 0.63.0, 4):
|
|
163
|
+
* the document's own words ("CANCELLED"; 14's "CANCELLED", "SUCCESS") and
|
|
164
|
+
* their spelling variants. ⚠️ NOT A PATTERN: /CANCEL|CLOSED|SUCCESS/ took
|
|
165
|
+
* CANCEL_FAILED and NOT_CANCELLABLE as done. Anything else is not done; no
|
|
166
|
+
* status at all is not known (`cancelOutcome`).
|
|
167
|
+
*/
|
|
168
|
+
export const CANCELLED_STATUSES = new Set([
|
|
169
|
+
'CANCELLED',
|
|
170
|
+
'CANCELED',
|
|
171
|
+
'CLOSED',
|
|
172
|
+
'SUCCESS',
|
|
173
|
+
]);
|
|
174
|
+
/**
|
|
175
|
+
* What a cancellation's answer says: `done` - `success` not false and a status
|
|
176
|
+
* in `CANCELLED_STATUSES`; `refused` - `success` false, or another status;
|
|
177
|
+
* `unknown` - no status said (an empty answer): nothing is changed on our side,
|
|
178
|
+
* and the guest is told so.
|
|
179
|
+
*/
|
|
180
|
+
export const cancelOutcome = (out) => {
|
|
181
|
+
if (out?.success === false)
|
|
182
|
+
return 'refused';
|
|
183
|
+
const s = String(out?.status ?? '')
|
|
184
|
+
.trim()
|
|
185
|
+
.toUpperCase();
|
|
186
|
+
if (!s)
|
|
187
|
+
return 'unknown';
|
|
188
|
+
return CANCELLED_STATUSES.has(s) ? 'done' : 'refused';
|
|
189
|
+
};
|
|
112
190
|
const TERMS_TEXT_KEYS = ['terms', 'terms_text', 'termsText', 'terms_content', 'termsContent'];
|
|
113
191
|
const TERMS_TOKEN_KEYS = ['terms_token', 'termsToken'];
|
|
114
192
|
const isCode = (err, code) => err instanceof OtalessError && !(err instanceof OtalessBusy) && err.backendCode === code;
|
|
@@ -166,7 +244,7 @@ export const createOtalessBookings = (deps) => {
|
|
|
166
244
|
group,
|
|
167
245
|
};
|
|
168
246
|
};
|
|
169
|
-
const signInFirst = (groups) =>
|
|
247
|
+
const signInFirst = (groups) => signInRefusal('sign-in', `Nothing was booked: booking at ${groups.map((g) => deps.groupOf(g).name).join(' and ')} needs the guest signed in there through their ${deps.brand} account - ask them to sign in first.`, groups);
|
|
170
248
|
/**
|
|
171
249
|
* One of this guest's orders, by its id or the code the guest quotes, with
|
|
172
250
|
* their sign-in at its group - never an order of anyone else, and never one
|
|
@@ -181,6 +259,10 @@ export const createOtalessBookings = (deps) => {
|
|
|
181
259
|
? [orders.get(id)]
|
|
182
260
|
: [...orders.values()].filter((o) => !!o.code && o.code.toLowerCase() === low);
|
|
183
261
|
for (const r of named) {
|
|
262
|
+
// ⚠️ LET GO AT ONCE, NOT THE GUEST'S TO ACT ON (总线程's review of 0.63.0, 7):
|
|
263
|
+
// one that could not be undone is a person's.
|
|
264
|
+
if (r.released)
|
|
265
|
+
continue;
|
|
184
266
|
const acct = accountFor(who, r.group);
|
|
185
267
|
if (acct && acct.owner === r.owner)
|
|
186
268
|
return { r, acct };
|
|
@@ -286,14 +368,14 @@ export const createOtalessBookings = (deps) => {
|
|
|
286
368
|
sessions.delete(sessionKey(acct));
|
|
287
369
|
deps.auth?.expired?.(acct.key, acct.group);
|
|
288
370
|
const name = deps.groupOf(acct.group).name;
|
|
289
|
-
throw
|
|
371
|
+
throw signInRefusal('session-expired', `${name} says the guest's sign-in there is over, so nothing was done - ask them to sign in to ${name} through their ${deps.brand} account again.`, [acct.group]);
|
|
290
372
|
}
|
|
291
373
|
};
|
|
292
374
|
const signedOut = (acct) => {
|
|
293
375
|
sessions.delete(sessionKey(acct));
|
|
294
376
|
deps.auth?.expired?.(acct.key, acct.group);
|
|
295
377
|
const name = deps.groupOf(acct.group).name;
|
|
296
|
-
return
|
|
378
|
+
return signInRefusal('signed-out', `The guest's sign-in at ${name} is over, so nothing was done - ask them to sign in to ${name} through their ${deps.brand} account again.`, [acct.group]);
|
|
297
379
|
};
|
|
298
380
|
// ── an order, as a booking ────────────────────────────────────────────────
|
|
299
381
|
const paymentOf = (r) => {
|
|
@@ -421,7 +503,8 @@ export const createOtalessBookings = (deps) => {
|
|
|
421
503
|
providerCode: a.group,
|
|
422
504
|
reason: 'price or payment page not as quoted',
|
|
423
505
|
}, cred, deps.callerOf(a.who)));
|
|
424
|
-
|
|
506
|
+
// Not said to be done - refused, or not known: a person, as any failure here.
|
|
507
|
+
if (cancelOutcome(done) !== 'done')
|
|
425
508
|
throw new Error('not cancelled');
|
|
426
509
|
r.status = 'cancelled';
|
|
427
510
|
r.cancelledAt = iso();
|
|
@@ -655,19 +738,34 @@ export const createOtalessBookings = (deps) => {
|
|
|
655
738
|
const group = hotel.supplier;
|
|
656
739
|
const acct = accountFor(who, group);
|
|
657
740
|
if (!acct) {
|
|
658
|
-
failed.push(failedStay(label, signInFirst([group]).message));
|
|
741
|
+
failed.push({ ...failedStay(label, signInFirst([group]).message), groups: [group] });
|
|
659
742
|
continue;
|
|
660
743
|
}
|
|
661
|
-
// A second press, a lost answer: the order already made for this stay.
|
|
662
744
|
const lockKey = `${acct.owner}|${hotel.id}|${line.roomRef}|${stay.checkIn}|${stay.checkOut}|${rooms}`;
|
|
663
|
-
const
|
|
745
|
+
const sameStay = (o) => o.owner === acct.owner &&
|
|
746
|
+
!o.released &&
|
|
664
747
|
o.hotelId === hotel.id &&
|
|
665
748
|
o.roomId === line.roomRef &&
|
|
666
749
|
o.stay.checkIn === stay.checkIn &&
|
|
667
750
|
o.stay.checkOut === stay.checkOut &&
|
|
668
|
-
o.rooms === rooms
|
|
669
|
-
|
|
670
|
-
|
|
751
|
+
o.rooms === rooms;
|
|
752
|
+
// ⚠️ AN EARLIER ORDER OF THIS STAY THAT MAY HAVE BEEN MADE IS LOOKED FOR
|
|
753
|
+
// FIRST, HOWEVER OLD (总线程's review of 0.63.0, 5): the group's order list
|
|
754
|
+
// (12) is read; not found there - or not readable - nothing new is sent.
|
|
755
|
+
const unknown = [...orders.values()].filter((o) => sameStay(o) && o.status === 'unconfirmed');
|
|
756
|
+
if (unknown.length) {
|
|
757
|
+
const read = await lookAtOrders(acct, who, group, unknown);
|
|
758
|
+
if (!read || unknown.some((o) => o.status === 'unconfirmed')) {
|
|
759
|
+
failed.push(failedStay(label, `An earlier booking of this stay is still being looked into with ${deps.groupOf(group).name} - whether it was made is not known yet, so nothing new was booked. Look at the bookings again in a few minutes.`));
|
|
760
|
+
continue;
|
|
761
|
+
}
|
|
762
|
+
}
|
|
763
|
+
// A second press, a lost answer, an order found in the list: the order
|
|
764
|
+
// already made for this stay, while it may still be paid - with no time to
|
|
765
|
+
// pay by known, until 15 or 12 says otherwise. Never a second one beside it.
|
|
766
|
+
const before = [...orders.values()].find((o) => sameStay(o) &&
|
|
767
|
+
o.status === 'awaiting-payment' &&
|
|
768
|
+
(now() - Date.parse(o.createdAt) < REPEAT_MS || !o.payBy || now() < Date.parse(o.payBy)));
|
|
671
769
|
if (before) {
|
|
672
770
|
booked.push(toBooking(before));
|
|
673
771
|
reused.push(before.id);
|
|
@@ -744,9 +842,15 @@ export const createOtalessBookings = (deps) => {
|
|
|
744
842
|
else if (!booked.length && !terms.length)
|
|
745
843
|
throw err;
|
|
746
844
|
else
|
|
747
|
-
failed.push(
|
|
748
|
-
|
|
749
|
-
|
|
845
|
+
failed.push({
|
|
846
|
+
...failedStay(label, err instanceof Error && 'code' in err
|
|
847
|
+
? err.message
|
|
848
|
+
: `${name} did not take it, so nothing was booked.`),
|
|
849
|
+
// A later stay's sign-in over: the group to sign in at again, as the refusal names it.
|
|
850
|
+
...(Array.isArray(err.groups)
|
|
851
|
+
? { groups: [...err.groups] }
|
|
852
|
+
: {}),
|
|
853
|
+
});
|
|
750
854
|
}
|
|
751
855
|
finally {
|
|
752
856
|
inFlight.delete(lockKey);
|
|
@@ -885,14 +989,22 @@ export const createOtalessBookings = (deps) => {
|
|
|
885
989
|
log(`[otaless] payment status of an order at ${r.group} not read: ${err instanceof Error ? err.name : 'error'}`);
|
|
886
990
|
}
|
|
887
991
|
};
|
|
888
|
-
/**
|
|
992
|
+
/**
|
|
993
|
+
* The group's order list (12): statuses, a lost payment link, and an order
|
|
994
|
+
* 13 did not answer for. True when the list was read - false when it could
|
|
995
|
+
* not be (and nothing changed).
|
|
996
|
+
*
|
|
997
|
+
* ⚠️ WHAT IS LET GO OR STILL BEING LOOKED FOR IS NOT TOUCHED (总线程's review
|
|
998
|
+
* of 0.63.0, 3 and 7): a released order gets no status and no payment link
|
|
999
|
+
* back; an unconfirmed one moves only by being claimed, below.
|
|
1000
|
+
*/
|
|
889
1001
|
const lookAtOrders = async (acct, who, group, mine) => {
|
|
890
1002
|
let rows;
|
|
891
1003
|
try {
|
|
892
1004
|
rows = await withSession(acct, who, (cred) => client.orders({ providerCode: group }, cred, deps.callerOf(who)));
|
|
893
1005
|
}
|
|
894
1006
|
catch {
|
|
895
|
-
return;
|
|
1007
|
+
return false;
|
|
896
1008
|
}
|
|
897
1009
|
const known = new Set(orders.keys());
|
|
898
1010
|
for (const row of rows) {
|
|
@@ -900,7 +1012,9 @@ export const createOtalessBookings = (deps) => {
|
|
|
900
1012
|
if (!id)
|
|
901
1013
|
continue;
|
|
902
1014
|
const r = orders.get(id);
|
|
903
|
-
if (r
|
|
1015
|
+
if (r) {
|
|
1016
|
+
if (r.owner !== acct.owner || r.released || r.status === 'unconfirmed')
|
|
1017
|
+
continue;
|
|
904
1018
|
const s = statusOfRow(row.status);
|
|
905
1019
|
// ⚠️ AN UNPAID ORDER STAYS WAITING ("CONFIRMED" is not paid, questions
|
|
906
1020
|
// #53): only PAID, a cancellation or a failure moves it.
|
|
@@ -925,11 +1039,24 @@ export const createOtalessBookings = (deps) => {
|
|
|
925
1039
|
}
|
|
926
1040
|
if (known.has(id))
|
|
927
1041
|
continue;
|
|
928
|
-
//
|
|
1042
|
+
// ── an order 13 did not answer for (总线程's review of 0.63.0, 3) ──
|
|
1043
|
+
// ⚠️ THE SAME HOTEL, THE SAME ROOM, THE SAME NIGHTS - BY ID: the group and
|
|
1044
|
+
// the nights alone would claim another stay of the guest's. The document's
|
|
1045
|
+
// order rows carry no hotel or room id; until the backend sends them
|
|
1046
|
+
// (questions, 11-10 late), no row is claimed and the stay stays "being
|
|
1047
|
+
// looked into" - for a person.
|
|
1048
|
+
const hotelId = text(row.unifiedHotelId) ?? text(row.hotelId);
|
|
1049
|
+
const roomId = text(row.unifiedRoomId) ?? text(row.roomId);
|
|
929
1050
|
const dates = String(row.dates ?? '');
|
|
930
1051
|
const waiting = mine.filter((o) => o.status === 'unconfirmed' &&
|
|
931
1052
|
o.id.startsWith('pending:') &&
|
|
1053
|
+
!o.released &&
|
|
1054
|
+
o.owner === acct.owner &&
|
|
932
1055
|
o.group === group &&
|
|
1056
|
+
!!hotelId &&
|
|
1057
|
+
!!roomId &&
|
|
1058
|
+
o.hotelId === hotelId &&
|
|
1059
|
+
o.roomId === roomId &&
|
|
933
1060
|
dates.includes(o.stay.checkIn) &&
|
|
934
1061
|
dates.includes(o.stay.checkOut));
|
|
935
1062
|
if (waiting.length !== 1)
|
|
@@ -938,33 +1065,29 @@ export const createOtalessBookings = (deps) => {
|
|
|
938
1065
|
if (!o)
|
|
939
1066
|
continue;
|
|
940
1067
|
const charged = moneyOf(row.totalAmount, row.currency);
|
|
1068
|
+
// ⚠️ AT ANOTHER AMOUNT, NOT CLAIMED: the record keeps its own id and stays
|
|
1069
|
+
// unconfirmed - for a person.
|
|
1070
|
+
if (!charged || !(same(charged, o.quoted) || same(charged, o.quotedUsd))) {
|
|
1071
|
+
log(`[otaless] NEEDS A PERSON: an order 13 did not answer for was found at ${group} at another amount - not claimed`);
|
|
1072
|
+
continue;
|
|
1073
|
+
}
|
|
1074
|
+
const s = statusOfRow(row.status);
|
|
1075
|
+
const ok = payPageOf(text(row.checkoutUrl ?? undefined), deps.checkoutHosts);
|
|
941
1076
|
orders.delete(o.id);
|
|
942
1077
|
o.id = id;
|
|
943
1078
|
o.code = text(row.originalOrderId) ?? '';
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
log(`[otaless] NEEDS A PERSON: an order 13 did not answer for was found at ${group} at another amount`);
|
|
1079
|
+
o.charged = charged;
|
|
1080
|
+
// ⚠️ PAID IS ONLY "PAID": "CONFIRMED" unpaid is still waiting for its payment.
|
|
1081
|
+
if (s.paid) {
|
|
1082
|
+
o.status = 'confirmed';
|
|
1083
|
+
o.paid = true;
|
|
950
1084
|
}
|
|
951
|
-
else if (s.status) {
|
|
952
|
-
o.status =
|
|
953
|
-
s.status === 'confirmed' && !s.paid && text(row.checkoutUrl ?? undefined)
|
|
954
|
-
? 'awaiting-payment'
|
|
955
|
-
: s.status;
|
|
956
|
-
if (s.paid)
|
|
957
|
-
o.paid = true;
|
|
958
|
-
const ok = payPageOf(text(row.checkoutUrl ?? undefined), deps.checkoutHosts);
|
|
959
|
-
if (ok && o.status === 'awaiting-payment') {
|
|
960
|
-
o.payHost = ok.host;
|
|
961
|
-
payLinks.set(id, ok.url);
|
|
962
|
-
}
|
|
1085
|
+
else if (s.status === 'cancelled' || s.status === 'failed') {
|
|
1086
|
+
o.status = s.status;
|
|
963
1087
|
}
|
|
964
|
-
else
|
|
965
|
-
|
|
1088
|
+
else {
|
|
1089
|
+
o.status = 'awaiting-payment';
|
|
966
1090
|
if (ok) {
|
|
967
|
-
o.status = 'awaiting-payment';
|
|
968
1091
|
o.payHost = ok.host;
|
|
969
1092
|
payLinks.set(id, ok.url);
|
|
970
1093
|
}
|
|
@@ -972,6 +1095,7 @@ export const createOtalessBookings = (deps) => {
|
|
|
972
1095
|
known.add(id);
|
|
973
1096
|
put(o);
|
|
974
1097
|
}
|
|
1098
|
+
return true;
|
|
975
1099
|
};
|
|
976
1100
|
/** The guest's orders brought up to date, each by their sign-in at its group (`signed`). */
|
|
977
1101
|
const refresh = async (who, mine, signed) => {
|
|
@@ -1090,8 +1214,12 @@ export const createOtalessBookings = (deps) => {
|
|
|
1090
1214
|
const out = await withSession(acct, who, (cred) => unpaid
|
|
1091
1215
|
? client.cancelCheckout({ unifiedOrderId: r.id, providerCode: r.group, ...(why ? { reason: why } : {}) }, cred, deps.callerOf(who))
|
|
1092
1216
|
: client.cancelBooking({ unifiedOrderId: r.id, providerCode: r.group, ...(why ? { reason: why } : {}) }, cred, deps.callerOf(who)));
|
|
1093
|
-
const
|
|
1094
|
-
|
|
1217
|
+
const said = cancelOutcome(out);
|
|
1218
|
+
// ⚠️ NOTHING SAID IS NOT DONE (总线程's review of 0.63.0, 4): our record
|
|
1219
|
+
// stays as it was, and the guest is told it is not known yet.
|
|
1220
|
+
if (said === 'unknown')
|
|
1221
|
+
throw refusal('cancel-unknown', `${g} answered without saying whether it cancelled it, so nothing is changed here - look at the bookings again in a few minutes before asking again.`);
|
|
1222
|
+
if (said === 'refused')
|
|
1095
1223
|
throw refusal('not-cancelled', `${g} did not cancel it - it stands as it was.`);
|
|
1096
1224
|
r.status = 'cancelled';
|
|
1097
1225
|
r.cancelledAt = iso();
|
|
@@ -1102,8 +1230,44 @@ export const createOtalessBookings = (deps) => {
|
|
|
1102
1230
|
put(r);
|
|
1103
1231
|
return toBooking(r);
|
|
1104
1232
|
};
|
|
1105
|
-
// ── refund,
|
|
1106
|
-
|
|
1233
|
+
// ── refund: a preview, then the refund it previewed (9.1; 总线程's review of 0.63.0, B) ──
|
|
1234
|
+
/** Refund previews waiting to be sent, by their `preview`. */
|
|
1235
|
+
const refundPreviews = new Map();
|
|
1236
|
+
const refundable = (r) => {
|
|
1237
|
+
if (!r.paid)
|
|
1238
|
+
throw refusal('not-paid', 'Nothing was paid for this booking, so there is nothing to refund.');
|
|
1239
|
+
};
|
|
1240
|
+
const previewRefund = async (ref, who) => {
|
|
1241
|
+
const own = ownOrder(ref, who);
|
|
1242
|
+
if (!own)
|
|
1243
|
+
return null;
|
|
1244
|
+
const { r } = own;
|
|
1245
|
+
if (r.refund)
|
|
1246
|
+
throw refusal('refunded', 'A refund was already asked for this booking.');
|
|
1247
|
+
refundable(r);
|
|
1248
|
+
for (const [k, v] of refundPreviews)
|
|
1249
|
+
if (now() - v.at > REFUND_PREVIEW_MS || v.orderId === r.id)
|
|
1250
|
+
refundPreviews.delete(k);
|
|
1251
|
+
while (refundPreviews.size >= PENDING_MAX) {
|
|
1252
|
+
const first = refundPreviews.keys().next().value;
|
|
1253
|
+
if (first === undefined)
|
|
1254
|
+
break;
|
|
1255
|
+
refundPreviews.delete(first);
|
|
1256
|
+
}
|
|
1257
|
+
const amount = r.charged ?? r.quoted;
|
|
1258
|
+
const preview = randomBytes(18).toString('base64url');
|
|
1259
|
+
refundPreviews.set(preview, { orderId: r.id, owner: r.owner, amount, at: now() });
|
|
1260
|
+
return {
|
|
1261
|
+
preview,
|
|
1262
|
+
bookingId: r.id,
|
|
1263
|
+
confirmationCode: r.code || r.id,
|
|
1264
|
+
supplier: r.group,
|
|
1265
|
+
amount,
|
|
1266
|
+
terms: r.terms ?? '',
|
|
1267
|
+
until: iso(now() + REFUND_PREVIEW_MS),
|
|
1268
|
+
};
|
|
1269
|
+
};
|
|
1270
|
+
const refund = async (ref, who, reason, preview) => {
|
|
1107
1271
|
const own = ownOrder(ref, who);
|
|
1108
1272
|
if (!own)
|
|
1109
1273
|
return null;
|
|
@@ -1111,8 +1275,18 @@ export const createOtalessBookings = (deps) => {
|
|
|
1111
1275
|
if (r.refund)
|
|
1112
1276
|
return toBooking(r);
|
|
1113
1277
|
const g = deps.groupOf(r.group).name;
|
|
1114
|
-
|
|
1115
|
-
|
|
1278
|
+
refundable(r);
|
|
1279
|
+
// ⚠️ THE PREVIEW OF THIS VERY BOOKING, FOR THIS GUEST, AT THIS AMOUNT, ONCE
|
|
1280
|
+
// (总线程's review of 0.63.0, B): nothing is sent without it.
|
|
1281
|
+
const shown = preview ? refundPreviews.get(preview) : undefined;
|
|
1282
|
+
if (preview)
|
|
1283
|
+
refundPreviews.delete(preview);
|
|
1284
|
+
if (!shown ||
|
|
1285
|
+
now() - shown.at > REFUND_PREVIEW_MS ||
|
|
1286
|
+
shown.orderId !== r.id ||
|
|
1287
|
+
shown.owner !== r.owner ||
|
|
1288
|
+
!same(shown.amount, r.charged ?? r.quoted))
|
|
1289
|
+
throw refusal('refund-preview', 'Nothing was asked: a refund is asked only after the guest was shown what it asks for (the refund preview of this booking) - show it to them again first.');
|
|
1116
1290
|
const why = cleanReason(reason);
|
|
1117
1291
|
// ⚠️ ALL OF IT, NEVER A PART (`amountUsd` is never sent), and no
|
|
1118
1292
|
// `sessionToken` (questions #53): the backend takes the guest from the sign-in.
|
|
@@ -1140,7 +1314,11 @@ export const createOtalessBookings = (deps) => {
|
|
|
1140
1314
|
per_night: 'night',
|
|
1141
1315
|
per_guest_per_day: 'person-night',
|
|
1142
1316
|
};
|
|
1317
|
+
/** Add-ons after booking, off unless the deployment turns them on (总线程's review of 0.63.0, A). */
|
|
1318
|
+
const addonsOff = () => refusal('addons-off', 'Nothing can be added to a booking here.');
|
|
1143
1319
|
const addons = async (ref, who) => {
|
|
1320
|
+
if (!deps.addonsOn)
|
|
1321
|
+
throw addonsOff();
|
|
1144
1322
|
const own = ownOrder(ref, who);
|
|
1145
1323
|
if (!own?.r.code)
|
|
1146
1324
|
return null;
|
|
@@ -1167,6 +1345,8 @@ export const createOtalessBookings = (deps) => {
|
|
|
1167
1345
|
return out;
|
|
1168
1346
|
};
|
|
1169
1347
|
const bookAddon = async (ref, extraId, details, who) => {
|
|
1348
|
+
if (!deps.addonsOn)
|
|
1349
|
+
throw addonsOff();
|
|
1170
1350
|
const own = ownOrder(ref, who);
|
|
1171
1351
|
if (!own?.r.code)
|
|
1172
1352
|
return null;
|
|
@@ -1209,6 +1389,7 @@ export const createOtalessBookings = (deps) => {
|
|
|
1209
1389
|
return found ? view(found.p) : undefined;
|
|
1210
1390
|
},
|
|
1211
1391
|
acceptTerms,
|
|
1392
|
+
previewRefund,
|
|
1212
1393
|
refund,
|
|
1213
1394
|
addons,
|
|
1214
1395
|
bookAddon,
|