@curless/hotel-storefront 0.80.2 → 0.81.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/index.d.ts +14 -0
- package/dist/account/index.d.ts.map +1 -1
- package/dist/account/index.js +427 -43
- package/dist/account/index.js.map +1 -1
- package/dist/account/pages.d.ts +15 -2
- package/dist/account/pages.d.ts.map +1 -1
- package/dist/account/pages.js +13 -10
- package/dist/account/pages.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 +18 -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 +48 -2
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +14 -1
- package/dist/config.js.map +1 -1
- package/dist/huazhu/ari-sync.d.ts.map +1 -1
- package/dist/huazhu/ari-sync.js +15 -4
- package/dist/huazhu/ari-sync.js.map +1 -1
- package/dist/huazhu/check.d.ts.map +1 -1
- package/dist/huazhu/check.js +4 -1
- package/dist/huazhu/check.js.map +1 -1
- package/dist/huazhu/client.d.ts +48 -2
- package/dist/huazhu/client.d.ts.map +1 -1
- package/dist/huazhu/client.js +263 -3
- package/dist/huazhu/client.js.map +1 -1
- package/dist/huazhu/make.d.ts.map +1 -1
- package/dist/huazhu/make.js +6 -1
- package/dist/huazhu/make.js.map +1 -1
- package/dist/legal.d.ts.map +1 -1
- package/dist/legal.js +26 -4
- package/dist/legal.js.map +1 -1
- package/dist/otaless/client.d.ts +109 -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 +92 -0
- package/dist/otaless/fake.d.ts.map +1 -1
- package/dist/otaless/fake.js +265 -0
- package/dist/otaless/fake.js.map +1 -1
- package/dist/otaless/make.d.ts +40 -1
- package/dist/otaless/make.d.ts.map +1 -1
- package/dist/otaless/make.js +150 -2
- package/dist/otaless/make.js.map +1 -1
- package/dist/otaless/shop-answers.d.ts +72 -0
- package/dist/otaless/shop-answers.d.ts.map +1 -0
- package/dist/otaless/shop-answers.js +344 -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 +100 -0
- package/dist/otaless/shop-fake.d.ts.map +1 -0
- package/dist/otaless/shop-fake.js +259 -0
- package/dist/otaless/shop-fake.js.map +1 -0
- package/dist/otaless/shop-service.d.ts +105 -0
- package/dist/otaless/shop-service.d.ts.map +1 -0
- package/dist/otaless/shop-service.js +187 -0
- package/dist/otaless/shop-service.js.map +1 -0
- package/dist/otaless/shop.d.ts +160 -0
- package/dist/otaless/shop.d.ts.map +1 -0
- package/dist/otaless/shop.js +715 -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 +41 -12
- 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 +14 -0
- package/dist/surface.js.map +1 -1
- package/dist/tools.d.ts +98 -93
- package/dist/tools.d.ts.map +1 -1
- package/dist/tools.js +239 -1
- package/dist/tools.js.map +1 -1
- package/package.json +1 -1
package/dist/otaless/fake.d.ts
CHANGED
|
@@ -265,6 +265,66 @@ export type FakeTermsSession = {
|
|
|
265
265
|
expired?: true;
|
|
266
266
|
orderId?: string;
|
|
267
267
|
};
|
|
268
|
+
/** The wallet's paths (17.1-17.7) a knob can name. */
|
|
269
|
+
export type FakeWalletPath = 'link-session' | 'balance' | 'authorize' | 'limits' | 'transactions' | 'renew' | 'unbind';
|
|
270
|
+
/** How the wallet (17.1-17.7) answers from now on - `OtalessFake.wallet`. Merged into what is set. */
|
|
271
|
+
export type FakeWalletKnobs = {
|
|
272
|
+
/** 17.1 hands this out as `linkUrl` instead of its own - to try a host that is not allowed. */
|
|
273
|
+
walletLinkUrl?: string;
|
|
274
|
+
/**
|
|
275
|
+
* The next request to this path is APPLIED on the fake but its answer never arrives (the
|
|
276
|
+
* request times out) - so a test can prove it was not sent again. Taken once.
|
|
277
|
+
*/
|
|
278
|
+
timeoutNext?: FakeWalletPath;
|
|
279
|
+
/**
|
|
280
|
+
* 17.3 refuses and nothing is changed: `true` answers `code: 500` (what the backend answers
|
|
281
|
+
* its errors with today - read by us as NOT KNOWN, it may come after the write was applied);
|
|
282
|
+
* a number answers that business code instead (read as a plain no). Which code a declined
|
|
283
|
+
* card gets is questions #104.
|
|
284
|
+
*/
|
|
285
|
+
declineAuthorize?: boolean | number;
|
|
286
|
+
/** Every wallet path answers 4012: the member has not linked this group (questions #106). */
|
|
287
|
+
notLinked?: boolean;
|
|
288
|
+
/**
|
|
289
|
+
* `false`: 17.2 answers `limits: null` though limits ARE set (what the real backend did in the
|
|
290
|
+
* 11-23 live walkthrough) - 17.4 still echoes them. Default true.
|
|
291
|
+
*/
|
|
292
|
+
limitsInBalance?: boolean;
|
|
293
|
+
/** `true`: 17.7 answers `releasedUsd: null` (the real backend's 11-23 answer); the card is still removed. */
|
|
294
|
+
releasedUsdNull?: boolean;
|
|
295
|
+
};
|
|
296
|
+
/** A card the wallet holds, with its one credit line (all in cents). */
|
|
297
|
+
export type FakeWalletCard = {
|
|
298
|
+
id: string;
|
|
299
|
+
brand: string;
|
|
300
|
+
last4: string;
|
|
301
|
+
exp: string;
|
|
302
|
+
status: 'active' | 'removed';
|
|
303
|
+
authorized: number;
|
|
304
|
+
captured: number;
|
|
305
|
+
held: number;
|
|
306
|
+
/** ms since the epoch - the fake's own clock (`walletNow`). */
|
|
307
|
+
expiresAt?: number;
|
|
308
|
+
};
|
|
309
|
+
export type FakeWalletEntry = {
|
|
310
|
+
kind: string;
|
|
311
|
+
amountUsd: number;
|
|
312
|
+
currency: 'USD';
|
|
313
|
+
ref: string;
|
|
314
|
+
at: string;
|
|
315
|
+
note: string;
|
|
316
|
+
merchant: string;
|
|
317
|
+
actor: string;
|
|
318
|
+
};
|
|
319
|
+
/** One member's wallet at a group, as the fake keeps it. */
|
|
320
|
+
export type FakeWallet = {
|
|
321
|
+
cards: FakeWalletCard[];
|
|
322
|
+
ledger: FakeWalletEntry[];
|
|
323
|
+
limits: {
|
|
324
|
+
perTxnUsd: number | null;
|
|
325
|
+
perDayUsd: number | null;
|
|
326
|
+
};
|
|
327
|
+
};
|
|
268
328
|
export type OtalessFake = {
|
|
269
329
|
fetch: typeof fetch;
|
|
270
330
|
/** Every request it was sent, in order. */
|
|
@@ -294,6 +354,36 @@ export type OtalessFake = {
|
|
|
294
354
|
pay: (id: string) => void;
|
|
295
355
|
/** These tokens are signed out (401). */
|
|
296
356
|
signOut: (token: string) => void;
|
|
357
|
+
/** How the wallet (17.1-17.7) answers from now on - see `FakeWalletKnobs`. Merged into what is set. */
|
|
358
|
+
wallet: (k: FakeWalletKnobs) => void;
|
|
359
|
+
/** Every wallet kept, by `<member>|<group>`. */
|
|
360
|
+
wallets: Map<string, FakeWallet>;
|
|
361
|
+
/**
|
|
362
|
+
* The guest submits the hosted card page (`linkUrl`'s `sid`): the card is added to their
|
|
363
|
+
* wallet. One use, 15 minutes - `expired` and `used` otherwise, `unknown` for any other sid.
|
|
364
|
+
*/
|
|
365
|
+
walletSubmitCard: (sid: string, card: {
|
|
366
|
+
brand: string;
|
|
367
|
+
last4: string;
|
|
368
|
+
exp: string;
|
|
369
|
+
}) => {
|
|
370
|
+
ok: true;
|
|
371
|
+
cardId: string;
|
|
372
|
+
} | {
|
|
373
|
+
ok: false;
|
|
374
|
+
reason: 'expired' | 'used' | 'unknown';
|
|
375
|
+
};
|
|
376
|
+
/** The fake's clock for the wallet moves on (credit lines last 7 days, link pages 15 minutes). */
|
|
377
|
+
walletAdvance: (ms: number) => void;
|
|
378
|
+
/**
|
|
379
|
+
* A booking holds and/or charges part of a member's credit (what 8 does at the group,
|
|
380
|
+
* 17.2's `held` / `captured`) - in cents, from the first active card with a credit line.
|
|
381
|
+
*/
|
|
382
|
+
walletSpend: (member: string, group: string, s: {
|
|
383
|
+
bookingId: string;
|
|
384
|
+
heldCents?: number;
|
|
385
|
+
capturedCents?: number;
|
|
386
|
+
}) => void;
|
|
297
387
|
/**
|
|
298
388
|
* A guest signed in at a group, as the backend's `/ota/sign-in` hands it out
|
|
299
389
|
* (the document of 2026-11-10, its 3; robin 11-10: the Otaless account signs
|
|
@@ -322,6 +412,8 @@ export declare const RECORDED_1104: {
|
|
|
322
412
|
ascottSingapore: R<WireSearch>;
|
|
323
413
|
};
|
|
324
414
|
export declare const createOtalessFake: (opts?: {
|
|
415
|
+
/** The wallet's clock (default `Date.now`; `walletAdvance` moves it on). */
|
|
416
|
+
now?: () => number;
|
|
325
417
|
scene?: OtalessScene;
|
|
326
418
|
tenant?: string;
|
|
327
419
|
sites?: string[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fake.d.ts","sourceRoot":"","sources":["../../src/otaless/fake.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,CAAC,EAAE,gBAAgB,EAAE,SAAS,EAAa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EAAE,CAAC,CAAC,UAAU,CAAC,CAAA;CA2KhF,CAAC;AAKX,eAAO,MAAM,iBAAiB,GAC5B,OAAM;IACJ,4EAA4E;IAC5E,GAAG,CAAC,EAAE,MAAM,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,YAAY,CAAC;IACrB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;IACjB,wFAAwF;IACxF,UAAU,CAAC,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC;CACzB,KACL,WAq7BF,CAAC"}
|
package/dist/otaless/fake.js
CHANGED
|
@@ -1396,6 +1396,233 @@ export const createOtalessFake = (opts = {}) => {
|
|
|
1396
1396
|
}
|
|
1397
1397
|
return json({ code: 404, msg: 'Not Found' }, 404);
|
|
1398
1398
|
};
|
|
1399
|
+
// ---- The wallet, 17.1-17.7 (the 11-23 document). Kept per member and group. ----
|
|
1400
|
+
let walletKnobs = {};
|
|
1401
|
+
const wallets = new Map();
|
|
1402
|
+
const walletLinks = new Map();
|
|
1403
|
+
/** `idempotencyKey` -> the answer it was first given, by member and path. */
|
|
1404
|
+
const walletKeys = new Map();
|
|
1405
|
+
let walletSkew = 0;
|
|
1406
|
+
const walletNow = () => (opts.now ?? Date.now)() + walletSkew;
|
|
1407
|
+
const WEEK_MS = 7 * 24 * 60 * 60 * 1000;
|
|
1408
|
+
const LINK_MS = 15 * 60 * 1000;
|
|
1409
|
+
const usd = (cents) => Math.round(cents) / 100;
|
|
1410
|
+
const walletOf = (member, group) => {
|
|
1411
|
+
const k = `${member}|${group}`;
|
|
1412
|
+
let w = wallets.get(k);
|
|
1413
|
+
if (!w) {
|
|
1414
|
+
w = { cards: [], ledger: [], limits: { perTxnUsd: null, perDayUsd: null } };
|
|
1415
|
+
wallets.set(k, w);
|
|
1416
|
+
}
|
|
1417
|
+
return w;
|
|
1418
|
+
};
|
|
1419
|
+
const addEntry = (w, kind, cents, ref, actor = 'shopper') => {
|
|
1420
|
+
w.ledger.push({
|
|
1421
|
+
kind,
|
|
1422
|
+
amountUsd: usd(cents),
|
|
1423
|
+
currency: 'USD',
|
|
1424
|
+
ref,
|
|
1425
|
+
at: new Date(walletNow()).toISOString(),
|
|
1426
|
+
note: `${kind} (fake)`,
|
|
1427
|
+
merchant: 'Ji',
|
|
1428
|
+
actor,
|
|
1429
|
+
});
|
|
1430
|
+
};
|
|
1431
|
+
const lineExpired = (c) => c.expiresAt !== undefined && walletNow() >= c.expiresAt;
|
|
1432
|
+
/** 17.2's `credit`, summed over every line: `available = max(0, authorized - captured - held)`. */
|
|
1433
|
+
const creditOf = (w) => {
|
|
1434
|
+
const lines = w.cards.filter((c) => c.authorized > 0 || c.captured > 0 || c.held > 0);
|
|
1435
|
+
const authorized = lines.reduce((n, c) => n + c.authorized, 0);
|
|
1436
|
+
const captured = lines.reduce((n, c) => n + c.captured, 0);
|
|
1437
|
+
const held = lines.reduce((n, c) => n + c.held, 0);
|
|
1438
|
+
const live = lines.filter((c) => !lineExpired(c));
|
|
1439
|
+
const available = live.reduce((n, c) => n + Math.max(0, c.authorized - c.captured - c.held), 0);
|
|
1440
|
+
const ends = lines.map((c) => c.expiresAt).filter((t) => t !== undefined);
|
|
1441
|
+
const expiresAt = ends.length ? Math.max(...ends) : undefined;
|
|
1442
|
+
return {
|
|
1443
|
+
authorizedUsd: usd(authorized),
|
|
1444
|
+
capturedUsd: usd(captured),
|
|
1445
|
+
heldUsd: usd(held),
|
|
1446
|
+
availableUsd: usd(available),
|
|
1447
|
+
...(expiresAt !== undefined ? { expiresAt: new Date(expiresAt).toISOString() } : {}),
|
|
1448
|
+
expired: lines.length > 0 && live.length === 0,
|
|
1449
|
+
currency: 'USD',
|
|
1450
|
+
};
|
|
1451
|
+
};
|
|
1452
|
+
const limitsOf = (w) => ({
|
|
1453
|
+
...w.limits,
|
|
1454
|
+
perMerchantUsd: null,
|
|
1455
|
+
agentCapUsd: null,
|
|
1456
|
+
});
|
|
1457
|
+
const lost = () => {
|
|
1458
|
+
// The request was applied; the answer never comes - the client's own time limit.
|
|
1459
|
+
throw new DOMException('The operation timed out.', 'TimeoutError');
|
|
1460
|
+
};
|
|
1461
|
+
/** The wallet paths, or undefined for any other. */
|
|
1462
|
+
const walletAnswer = (url, method, body, auth) => {
|
|
1463
|
+
const path = url.pathname.replace(/^\/api\/v1\/ota\/wallet/, '');
|
|
1464
|
+
if (path === url.pathname)
|
|
1465
|
+
return undefined;
|
|
1466
|
+
const which = method === 'POST' &&
|
|
1467
|
+
/^\/(link-session|balance|authorize|limits|transactions|renew)$/.test(path)
|
|
1468
|
+
? path.slice(1)
|
|
1469
|
+
: method === 'DELETE' && /^\/cards\/[^/]+$/.test(path)
|
|
1470
|
+
? 'unbind'
|
|
1471
|
+
: undefined;
|
|
1472
|
+
if (!which)
|
|
1473
|
+
return json({ code: 404, msg: 'Not Found' }, 404);
|
|
1474
|
+
// The member's token alone is what the document asks.
|
|
1475
|
+
const member = auth ? members.get(auth) : undefined;
|
|
1476
|
+
if (!auth || !member || signedOut.has(auth))
|
|
1477
|
+
return json({ code: 401, msg: '未登录或登录已过期' });
|
|
1478
|
+
if (repeat) {
|
|
1479
|
+
repeat = false;
|
|
1480
|
+
return json({ code: 10014, msg: 'Repeat submit is not allowed' });
|
|
1481
|
+
}
|
|
1482
|
+
if (walletKnobs.notLinked)
|
|
1483
|
+
return json({
|
|
1484
|
+
code: 4012,
|
|
1485
|
+
msg: '未检测到有效的 MCP 连接会话 (Mcp-Session-Id),请先调用 /initialize 握手或登录该渠道',
|
|
1486
|
+
});
|
|
1487
|
+
const group = String(body?.providerCode ?? url.searchParams.get('providerCode') ?? '');
|
|
1488
|
+
if (!group)
|
|
1489
|
+
return json({ code: 400, msg: 'providerCode cannot be blank' });
|
|
1490
|
+
const w = walletOf(member, group);
|
|
1491
|
+
const timesOut = walletKnobs.timeoutNext === which;
|
|
1492
|
+
if (timesOut)
|
|
1493
|
+
walletKnobs = { ...walletKnobs, timeoutNext: undefined };
|
|
1494
|
+
const reply = (data) => (timesOut ? lost() : ok200(data));
|
|
1495
|
+
const ok200 = (data) => json({ code: 200, msg: '操作成功', data });
|
|
1496
|
+
const refuse = (msg) => json({ code: 500, msg });
|
|
1497
|
+
const cardOf = (id) => w.cards.find((c) => c.id === id && c.status === 'active');
|
|
1498
|
+
if (which === 'link-session') {
|
|
1499
|
+
const sid = `sid_${(++serial).toString(16).padStart(6, '0')}${Math.random().toString(16).slice(2, 8)}`;
|
|
1500
|
+
const expiresAt = walletNow() + LINK_MS;
|
|
1501
|
+
walletLinks.set(sid, { member, group, expiresAt, used: false });
|
|
1502
|
+
return reply({
|
|
1503
|
+
ok: true,
|
|
1504
|
+
linkUrl: walletKnobs.walletLinkUrl ?? `https://agent.curless.ai/wallet/link/${sid}`,
|
|
1505
|
+
expiresAt: new Date(expiresAt).toISOString(),
|
|
1506
|
+
cardsBefore: w.cards.filter((c) => c.status === 'active').length,
|
|
1507
|
+
cardTag: 'wallet_link',
|
|
1508
|
+
message: 'Please complete card binding at the secure link',
|
|
1509
|
+
});
|
|
1510
|
+
}
|
|
1511
|
+
if (which === 'balance') {
|
|
1512
|
+
const status = creditOf(w);
|
|
1513
|
+
return reply({
|
|
1514
|
+
ok: true,
|
|
1515
|
+
statusTag: status.expired ? 'Expired' : status.availableUsd > 0 ? 'Ready' : 'No credit',
|
|
1516
|
+
credit: status,
|
|
1517
|
+
cards: w.cards.map((c) => ({
|
|
1518
|
+
id: c.id,
|
|
1519
|
+
brand: c.brand,
|
|
1520
|
+
last4: c.last4,
|
|
1521
|
+
exp: c.exp,
|
|
1522
|
+
status: c.status,
|
|
1523
|
+
lines: [],
|
|
1524
|
+
})),
|
|
1525
|
+
limits: walletKnobs.limitsInBalance === false ? null : limitsOf(w),
|
|
1526
|
+
recentTransactions: [...w.ledger].reverse().slice(0, 8),
|
|
1527
|
+
cardTag: 'wallet_status',
|
|
1528
|
+
});
|
|
1529
|
+
}
|
|
1530
|
+
if (which === 'transactions') {
|
|
1531
|
+
const n = Number(body?.limit ?? 20);
|
|
1532
|
+
if (!Number.isInteger(n) || n < 1 || n > 50)
|
|
1533
|
+
return refuse('limit must be 1 to 50');
|
|
1534
|
+
// 17.5's own example is the bare body, not an R<T>.
|
|
1535
|
+
if (timesOut)
|
|
1536
|
+
return lost();
|
|
1537
|
+
return json({ transactions: [...w.ledger].reverse().slice(0, n) });
|
|
1538
|
+
}
|
|
1539
|
+
if (which === 'authorize') {
|
|
1540
|
+
const amount = Number(body?.amountUsd);
|
|
1541
|
+
if (!(amount > 0 && amount <= 2000))
|
|
1542
|
+
return refuse('amountUsd must be above 0 and at most 2000');
|
|
1543
|
+
const key = typeof body?.idempotencyKey === 'string' ? body.idempotencyKey : '';
|
|
1544
|
+
const kept = key ? walletKeys.get(`${member}|${group}|authorize|${key}`) : undefined;
|
|
1545
|
+
if (kept)
|
|
1546
|
+
return reply(kept);
|
|
1547
|
+
if (walletKnobs.declineAuthorize)
|
|
1548
|
+
return typeof walletKnobs.declineAuthorize === 'number'
|
|
1549
|
+
? json({ code: walletKnobs.declineAuthorize, msg: 'authorization declined' })
|
|
1550
|
+
: refuse('authorization declined');
|
|
1551
|
+
// Absent `cardId`: "the first active card" (the document) - ours always sends one.
|
|
1552
|
+
const card = body?.cardId === undefined
|
|
1553
|
+
? w.cards.find((c) => c.status === 'active')
|
|
1554
|
+
: cardOf(body.cardId);
|
|
1555
|
+
if (!card)
|
|
1556
|
+
return refuse('card not found');
|
|
1557
|
+
const cents = Math.round(amount * 100);
|
|
1558
|
+
// ⚠️ ADDITIVE HERE - whether a second authorization adds to the credit or replaces it is
|
|
1559
|
+
// the backend's to say (questions #104).
|
|
1560
|
+
card.authorized += cents;
|
|
1561
|
+
card.expiresAt = walletNow() + WEEK_MS;
|
|
1562
|
+
addEntry(w, 'authorize', cents, `auth:${card.id}`, 'agent');
|
|
1563
|
+
const answer = {
|
|
1564
|
+
ok: true,
|
|
1565
|
+
simulated: true,
|
|
1566
|
+
walletId: `wallet_${group}_001`,
|
|
1567
|
+
credit: creditOf(w),
|
|
1568
|
+
message: `Authorized US$ ${amount.toFixed(2)} successfully`,
|
|
1569
|
+
};
|
|
1570
|
+
if (key)
|
|
1571
|
+
walletKeys.set(`${member}|${group}|authorize|${key}`, answer);
|
|
1572
|
+
return reply(answer);
|
|
1573
|
+
}
|
|
1574
|
+
if (which === 'limits') {
|
|
1575
|
+
const pick = (k) => body && k in body ? (body[k] === null ? null : Number(body[k])) : undefined;
|
|
1576
|
+
for (const k of ['perTransactionUsd', 'perDayUsd']) {
|
|
1577
|
+
const v = pick(k);
|
|
1578
|
+
if (typeof v === 'number' && !(v > 0 && v <= 2000))
|
|
1579
|
+
return refuse(`${k} out of range`);
|
|
1580
|
+
}
|
|
1581
|
+
// The document: absent keeps, null clears. (Whether the Java side tells them apart is
|
|
1582
|
+
// questions #108 - ours always sends both.)
|
|
1583
|
+
const t = pick('perTransactionUsd');
|
|
1584
|
+
const d = pick('perDayUsd');
|
|
1585
|
+
if (t !== undefined)
|
|
1586
|
+
w.limits.perTxnUsd = t;
|
|
1587
|
+
if (d !== undefined)
|
|
1588
|
+
w.limits.perDayUsd = d;
|
|
1589
|
+
return reply({
|
|
1590
|
+
ok: true,
|
|
1591
|
+
limits: limitsOf(w),
|
|
1592
|
+
message: 'Wallet limits updated successfully',
|
|
1593
|
+
});
|
|
1594
|
+
}
|
|
1595
|
+
if (which === 'renew') {
|
|
1596
|
+
const card = body?.cardId === undefined
|
|
1597
|
+
? w.cards.find((c) => c.status === 'active' && c.authorized > 0)
|
|
1598
|
+
: cardOf(body.cardId);
|
|
1599
|
+
if (!card || card.authorized <= 0 || card.expiresAt === undefined)
|
|
1600
|
+
return reply({ ok: false, credit: creditOf(w), message: 'nothing_to_renew' });
|
|
1601
|
+
card.expiresAt = Math.max(card.expiresAt, walletNow()) + WEEK_MS;
|
|
1602
|
+
addEntry(w, 'renew', 0, `auth:${card.id}`);
|
|
1603
|
+
return reply({
|
|
1604
|
+
ok: true,
|
|
1605
|
+
credit: creditOf(w),
|
|
1606
|
+
message: 'Successfully extended validity by 7 days',
|
|
1607
|
+
});
|
|
1608
|
+
}
|
|
1609
|
+
// unbind
|
|
1610
|
+
const id = decodeURIComponent(path.slice('/cards/'.length));
|
|
1611
|
+
const card = cardOf(id);
|
|
1612
|
+
if (!card)
|
|
1613
|
+
return refuse('card not found');
|
|
1614
|
+
const unused = lineExpired(card) ? 0 : Math.max(0, card.authorized - card.captured - card.held);
|
|
1615
|
+
card.status = 'removed';
|
|
1616
|
+
card.authorized -= unused;
|
|
1617
|
+
if (unused > 0)
|
|
1618
|
+
addEntry(w, 'expire', unused, `auth:${card.id}`);
|
|
1619
|
+
return reply({
|
|
1620
|
+
ok: true,
|
|
1621
|
+
unlinked: true,
|
|
1622
|
+
cardId: id,
|
|
1623
|
+
releasedUsd: walletKnobs.releasedUsdNull ? null : usd(unused),
|
|
1624
|
+
});
|
|
1625
|
+
};
|
|
1399
1626
|
const orders = new Map();
|
|
1400
1627
|
const sessions = new Set();
|
|
1401
1628
|
const signedOut = new Set();
|
|
@@ -1419,6 +1646,9 @@ export const createOtalessFake = (opts = {}) => {
|
|
|
1419
1646
|
...(auth ? { auth } : {}),
|
|
1420
1647
|
...(session ? { session } : {}),
|
|
1421
1648
|
});
|
|
1649
|
+
const walleted = walletAnswer(url, method, body, auth);
|
|
1650
|
+
if (walleted)
|
|
1651
|
+
return walleted;
|
|
1422
1652
|
const booked = bookingAnswer(url, method, body, auth, session);
|
|
1423
1653
|
if (booked)
|
|
1424
1654
|
return booked;
|
|
@@ -1612,6 +1842,41 @@ export const createOtalessFake = (opts = {}) => {
|
|
|
1612
1842
|
signOut: (token) => {
|
|
1613
1843
|
signedOut.add(token);
|
|
1614
1844
|
},
|
|
1845
|
+
wallet: (k) => {
|
|
1846
|
+
walletKnobs = { ...walletKnobs, ...k };
|
|
1847
|
+
},
|
|
1848
|
+
wallets,
|
|
1849
|
+
walletSubmitCard: (sid, card) => {
|
|
1850
|
+
const l = walletLinks.get(sid);
|
|
1851
|
+
if (!l)
|
|
1852
|
+
return { ok: false, reason: 'unknown' };
|
|
1853
|
+
if (l.used)
|
|
1854
|
+
return { ok: false, reason: 'used' };
|
|
1855
|
+
if (walletNow() >= l.expiresAt)
|
|
1856
|
+
return { ok: false, reason: 'expired' };
|
|
1857
|
+
l.used = true;
|
|
1858
|
+
const w = walletOf(l.member, l.group);
|
|
1859
|
+
const id = `fs_${(++serial).toString(16).padStart(8, '0')}`;
|
|
1860
|
+
w.cards.push({ id, ...card, status: 'active', authorized: 0, captured: 0, held: 0 });
|
|
1861
|
+
return { ok: true, cardId: id };
|
|
1862
|
+
},
|
|
1863
|
+
walletAdvance: (ms) => {
|
|
1864
|
+
walletSkew += ms;
|
|
1865
|
+
},
|
|
1866
|
+
walletSpend: (member, group, s) => {
|
|
1867
|
+
const w = walletOf(member, group);
|
|
1868
|
+
const line = w.cards.find((c) => c.status === 'active' && c.authorized > 0);
|
|
1869
|
+
if (!line)
|
|
1870
|
+
throw new Error('fake wallet: no credit line to spend from');
|
|
1871
|
+
if (s.heldCents) {
|
|
1872
|
+
line.held += s.heldCents;
|
|
1873
|
+
addEntry(w, 'hold', s.heldCents, `booking:${s.bookingId}`);
|
|
1874
|
+
}
|
|
1875
|
+
if (s.capturedCents) {
|
|
1876
|
+
line.captured += s.capturedCents;
|
|
1877
|
+
addEntry(w, 'capture', s.capturedCents, `booking:${s.bookingId}`);
|
|
1878
|
+
}
|
|
1879
|
+
},
|
|
1615
1880
|
signIn: (group, memberUserId) => {
|
|
1616
1881
|
const n = ++serial;
|
|
1617
1882
|
const token = `satoken_${group}_${n.toString(16).padStart(8, '0')}`;
|