@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
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import type { Booking, Identity } from '../types.js';
|
|
2
|
+
import { type OtalessShop, type ShopBuyResult, type ShopItem, type ShopLang, type ShopOrder, type ShopRead, type ShopWhy } from './shop.js';
|
|
3
|
+
/**
|
|
4
|
+
* A shop order's id: a UUID, as the backend makes them. ⚠️ THE RULE THAT TELLS A SHOP ORDER FROM A
|
|
5
|
+
* HOTEL ORDER: a hotel order is `<group>:<code>` (`atour:CM-1`), a bare confirmation code (`CM-1`,
|
|
6
|
+
* `OT4F2K9Q`) or `pending:<hex>` - none is a whole UUID, and a shop id is never looked for in the
|
|
7
|
+
* hotel records. The tools additionally take a UUID-shaped reference as a shop order only if the
|
|
8
|
+
* account's own shop orders hold it (`mine`), so a hotel code that happened to look like one is
|
|
9
|
+
* still the hotel's.
|
|
10
|
+
*/
|
|
11
|
+
export declare const SHOP_ORDER_ID: RegExp;
|
|
12
|
+
export declare const looksLikeShopOrder: (ref: string) => boolean;
|
|
13
|
+
export type ShopOrderKind = 'cancel' | 'refund';
|
|
14
|
+
export type ShopOrderPreview = {
|
|
15
|
+
ok: true;
|
|
16
|
+
kind: ShopOrderKind;
|
|
17
|
+
order: ShopOrder;
|
|
18
|
+
until: string;
|
|
19
|
+
} | {
|
|
20
|
+
ok: false;
|
|
21
|
+
why: ShopWhy | 'not-found' | 'not-open';
|
|
22
|
+
order?: ShopOrder;
|
|
23
|
+
};
|
|
24
|
+
export type ShopOrderOutcome = {
|
|
25
|
+
outcome: 'cancelled';
|
|
26
|
+
order: ShopOrder;
|
|
27
|
+
} | {
|
|
28
|
+
outcome: 'refunded';
|
|
29
|
+
order: ShopOrder;
|
|
30
|
+
refundCents?: number;
|
|
31
|
+
} | {
|
|
32
|
+
outcome: 'unknown';
|
|
33
|
+
kind: ShopOrderKind;
|
|
34
|
+
order: ShopOrder;
|
|
35
|
+
} | {
|
|
36
|
+
outcome: 'refused';
|
|
37
|
+
why: ShopWhy | 'not-found' | 'refund-preview' | 'in-progress' | 'checking' | 'not-open' | 'not-awaiting' | 'not-refundable' | 'failed';
|
|
38
|
+
order?: ShopOrder;
|
|
39
|
+
};
|
|
40
|
+
export type ShopBuyAsk = {
|
|
41
|
+
itemId: string;
|
|
42
|
+
option?: string;
|
|
43
|
+
quantity: number;
|
|
44
|
+
/** The guest's hotel confirmation code - an order of THIS account, live. */
|
|
45
|
+
booking: string;
|
|
46
|
+
unitCents: number;
|
|
47
|
+
currency: string;
|
|
48
|
+
lang: ShopLang;
|
|
49
|
+
};
|
|
50
|
+
export type ShopBuyAnswer = ShopBuyResult | {
|
|
51
|
+
outcome: 'booking-refused';
|
|
52
|
+
why: 'not-found' | 'not-live' | 'past';
|
|
53
|
+
};
|
|
54
|
+
export type OtalessShopApi = {
|
|
55
|
+
/** The one provider code the deployment sells through. */
|
|
56
|
+
readonly provider: string;
|
|
57
|
+
/** Buying is open (a checkout page only). */
|
|
58
|
+
readonly buyOpen: boolean;
|
|
59
|
+
items: (q: {
|
|
60
|
+
keyword?: string;
|
|
61
|
+
category?: string;
|
|
62
|
+
maxPrice?: number;
|
|
63
|
+
limit?: number;
|
|
64
|
+
lang: ShopLang;
|
|
65
|
+
}) => Promise<ShopRead<{
|
|
66
|
+
items: ShopItem[];
|
|
67
|
+
}>>;
|
|
68
|
+
item: (id: string, lang: ShopLang) => Promise<ShopRead<{
|
|
69
|
+
item: ShopItem;
|
|
70
|
+
}>>;
|
|
71
|
+
/** This account's orders now (awaiting ones re-checked). `not-signed-in` when nobody is. */
|
|
72
|
+
orders: (who: Identity, lang: ShopLang) => Promise<ShopRead<{
|
|
73
|
+
orders: ShopOrder[];
|
|
74
|
+
}>>;
|
|
75
|
+
/**
|
|
76
|
+
* Whether `ref` is a shop order of THIS account (a read; nothing is asked unless `ref` is UUID-shaped).
|
|
77
|
+
* `'shop-sign-in'`: the shop would not say - it needs its own sign-in (never "not found").
|
|
78
|
+
*/
|
|
79
|
+
mine: (who: Identity, ref: string, lang: ShopLang) => Promise<boolean | 'shop-sign-in'>;
|
|
80
|
+
/** What cancelling (unpaid) or refunding (paid, in full) the order would do. Changes nothing. Notes the preview. */
|
|
81
|
+
preview: (who: Identity, id: string, lang: ShopLang) => Promise<ShopOrderPreview>;
|
|
82
|
+
/** The cancel or the refund the guest was shown - once, in time, for the same order and amount. */
|
|
83
|
+
finish: (who: Identity, id: string, lang: ShopLang) => Promise<ShopOrderOutcome>;
|
|
84
|
+
buy: (who: Identity, ask: ShopBuyAsk) => Promise<ShopBuyAnswer>;
|
|
85
|
+
};
|
|
86
|
+
export type ShopServiceOptions = {
|
|
87
|
+
shop: OtalessShop;
|
|
88
|
+
provider: string;
|
|
89
|
+
buyOpen: boolean;
|
|
90
|
+
/** The conversation's own sign-in: the account's token and its id. Undefined: not signed in. */
|
|
91
|
+
tokenOf: (key: string) => {
|
|
92
|
+
token: string;
|
|
93
|
+
account?: string;
|
|
94
|
+
} | undefined;
|
|
95
|
+
/** The backend said the account's sign-in is over (401). */
|
|
96
|
+
signedOut?: (key: string) => void;
|
|
97
|
+
/** The conversation's own hotel booking by code (the hotel backend's `findBooking`). */
|
|
98
|
+
findBooking: (ref: string, who: Identity) => Promise<Booking | null>;
|
|
99
|
+
now: () => number;
|
|
100
|
+
previewMs?: number;
|
|
101
|
+
};
|
|
102
|
+
export declare const createShopService: (o: ShopServiceOptions) => OtalessShopApi;
|
|
103
|
+
/** Cents from a price a model passed (US$ or any currency's major units) - whole cents or nothing. */
|
|
104
|
+
export declare const unitCentsOf: (v: unknown) => number | undefined;
|
|
105
|
+
//# sourceMappingURL=shop-service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shop-service.d.ts","sourceRoot":"","sources":["../../src/otaless/shop-service.ts"],"names":[],"mappings":"AACA,OAAO,KA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G,SAGjD,CAAC"}
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { REFUND_PREVIEW_MS } from './booking.js';
|
|
3
|
+
import { centsOf, } from './shop.js';
|
|
4
|
+
// The add-on shop as the TOOLS see it (docs/otaless-hotels.md §17.6, phase 3): `OtalessShop` (the
|
|
5
|
+
// domain: catalogue, orders, cancel, refund, buy) plus what only the conversation knows - whose
|
|
6
|
+
// token it is, which hotel booking an order rides on, and what the guest was shown before a cancel
|
|
7
|
+
// or a refund. The tools hold no money rules of their own: every one is here or in shop.ts.
|
|
8
|
+
//
|
|
9
|
+
// ⚠️ THE ACCOUNT'S TOKEN NEVER LEAVES THIS FILE: it is read from the conversation's sign-in
|
|
10
|
+
// (`tokenOf`) for the one call and sent to the backend, nowhere else.
|
|
11
|
+
/**
|
|
12
|
+
* A shop order's id: a UUID, as the backend makes them. ⚠️ THE RULE THAT TELLS A SHOP ORDER FROM A
|
|
13
|
+
* HOTEL ORDER: a hotel order is `<group>:<code>` (`atour:CM-1`), a bare confirmation code (`CM-1`,
|
|
14
|
+
* `OT4F2K9Q`) or `pending:<hex>` - none is a whole UUID, and a shop id is never looked for in the
|
|
15
|
+
* hotel records. The tools additionally take a UUID-shaped reference as a shop order only if the
|
|
16
|
+
* account's own shop orders hold it (`mine`), so a hotel code that happened to look like one is
|
|
17
|
+
* still the hotel's.
|
|
18
|
+
*/
|
|
19
|
+
export const SHOP_ORDER_ID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
20
|
+
export const looksLikeShopOrder = (ref) => typeof ref === 'string' && SHOP_ORDER_ID.test(ref.trim());
|
|
21
|
+
const keyOf = (who) => who.tripOwner ?? who.sessionId;
|
|
22
|
+
const hash = (s) => createHash('sha256').update(s).digest('base64url').slice(0, 16);
|
|
23
|
+
const PREVIEWS_MAX = 200;
|
|
24
|
+
export const createShopService = (o) => {
|
|
25
|
+
const { shop, provider } = o;
|
|
26
|
+
const previewMs = o.previewMs ?? REFUND_PREVIEW_MS;
|
|
27
|
+
const iso = (t) => new Date(t).toISOString();
|
|
28
|
+
/** What each conversation was shown, by conversation and order: one use, `previewMs`. */
|
|
29
|
+
const previews = new Map();
|
|
30
|
+
const auth = (who) => {
|
|
31
|
+
const key = keyOf(who);
|
|
32
|
+
const a = o.tokenOf(key);
|
|
33
|
+
return a?.token
|
|
34
|
+
? { key, token: a.token, owner: a.account ? hash(`acct:${a.account}`) : hash(`conv:${key}`) }
|
|
35
|
+
: undefined;
|
|
36
|
+
};
|
|
37
|
+
const ended = (key, why) => {
|
|
38
|
+
if (why === 'not-signed-in')
|
|
39
|
+
o.signedOut?.(key);
|
|
40
|
+
};
|
|
41
|
+
const ownRow = async (token, id, lang, refresh) => {
|
|
42
|
+
const r = await shop.orders(token, provider, { lang, refresh });
|
|
43
|
+
if (!r.ok)
|
|
44
|
+
return { ok: false, why: r.why };
|
|
45
|
+
const order = r.orders.find((x) => x.id === id);
|
|
46
|
+
return order ? { ok: true, order } : { ok: false, why: 'not-found' };
|
|
47
|
+
};
|
|
48
|
+
const PAID = new Set(['paid', 'confirmed', 'completed']);
|
|
49
|
+
const kindOf = (order) => order.status === 'awaiting-payment' ? 'cancel' : PAID.has(order.status) ? 'refund' : undefined;
|
|
50
|
+
return {
|
|
51
|
+
provider,
|
|
52
|
+
buyOpen: o.buyOpen,
|
|
53
|
+
items: (q) => shop.items(provider, q),
|
|
54
|
+
item: (id, lang) => shop.item(provider, id, lang),
|
|
55
|
+
orders: async (who, lang) => {
|
|
56
|
+
const a = auth(who);
|
|
57
|
+
if (!a)
|
|
58
|
+
return { ok: false, why: 'not-signed-in' };
|
|
59
|
+
const r = await shop.orders(a.token, provider, { lang, refresh: true });
|
|
60
|
+
if (!r.ok)
|
|
61
|
+
ended(a.key, r.why);
|
|
62
|
+
return r;
|
|
63
|
+
},
|
|
64
|
+
mine: async (who, ref, lang) => {
|
|
65
|
+
// ⚠️ A hotel reference is never looked for among shop orders: no read is made for it.
|
|
66
|
+
if (!looksLikeShopOrder(ref))
|
|
67
|
+
return false;
|
|
68
|
+
const a = auth(who);
|
|
69
|
+
if (!a)
|
|
70
|
+
return false;
|
|
71
|
+
const r = await ownRow(a.token, ref.trim(), lang, false);
|
|
72
|
+
if (!r.ok)
|
|
73
|
+
ended(a.key, r.why);
|
|
74
|
+
// ⚠️ NOT "NOT MINE": a shop that wants its own sign-in has not said whose the order is.
|
|
75
|
+
return r.ok ? true : r.why === 'shop-sign-in' ? 'shop-sign-in' : false;
|
|
76
|
+
},
|
|
77
|
+
preview: async (who, id, lang) => {
|
|
78
|
+
const a = auth(who);
|
|
79
|
+
if (!a)
|
|
80
|
+
return { ok: false, why: 'not-signed-in' };
|
|
81
|
+
const r = await ownRow(a.token, id, lang, true);
|
|
82
|
+
if (!r.ok) {
|
|
83
|
+
ended(a.key, r.why);
|
|
84
|
+
return { ok: false, why: r.why };
|
|
85
|
+
}
|
|
86
|
+
const kind = kindOf(r.order);
|
|
87
|
+
if (!kind)
|
|
88
|
+
return { ok: false, why: 'not-open', order: r.order };
|
|
89
|
+
previews.set(`${a.key}|${id}`, {
|
|
90
|
+
kind,
|
|
91
|
+
cents: r.order.totalCents,
|
|
92
|
+
currency: r.order.currency,
|
|
93
|
+
owner: a.owner,
|
|
94
|
+
at: o.now(),
|
|
95
|
+
});
|
|
96
|
+
while (previews.size > PREVIEWS_MAX) {
|
|
97
|
+
const first = previews.keys().next().value;
|
|
98
|
+
if (first === undefined)
|
|
99
|
+
break;
|
|
100
|
+
previews.delete(first);
|
|
101
|
+
}
|
|
102
|
+
return { ok: true, kind, order: r.order, until: iso(o.now() + previewMs) };
|
|
103
|
+
},
|
|
104
|
+
finish: async (who, id, lang) => {
|
|
105
|
+
const a = auth(who);
|
|
106
|
+
if (!a)
|
|
107
|
+
return { outcome: 'refused', why: 'not-signed-in' };
|
|
108
|
+
const slot = `${a.key}|${id}`;
|
|
109
|
+
const shown = previews.get(slot);
|
|
110
|
+
previews.delete(slot); // one use, whatever comes of it
|
|
111
|
+
// ⚠️ THE PREVIEW OF THIS ORDER, FOR THIS ACCOUNT, IN TIME, ONCE: nothing is sent without it.
|
|
112
|
+
if (!shown || o.now() - shown.at > previewMs || shown.owner !== a.owner)
|
|
113
|
+
return { outcome: 'refused', why: 'refund-preview' };
|
|
114
|
+
// The order as it is NOW (no payment re-check: shop.cancel / shop.refund read it again themselves).
|
|
115
|
+
const r = await ownRow(a.token, id, lang, false);
|
|
116
|
+
if (!r.ok) {
|
|
117
|
+
ended(a.key, r.why);
|
|
118
|
+
return { outcome: 'refused', why: r.why };
|
|
119
|
+
}
|
|
120
|
+
const order = r.order;
|
|
121
|
+
// ⚠️ THE SAME ORDER, THE SAME KIND, THE SAME AMOUNT: a guest who was shown "nothing is charged"
|
|
122
|
+
// is not refunded money, and one shown US$75.65 is not refunded another figure.
|
|
123
|
+
if (kindOf(order) !== shown.kind ||
|
|
124
|
+
order.totalCents !== shown.cents ||
|
|
125
|
+
order.currency !== shown.currency)
|
|
126
|
+
return { outcome: 'refused', why: 'refund-preview', order };
|
|
127
|
+
if (shown.kind === 'cancel') {
|
|
128
|
+
const c = await shop.cancel(a.token, provider, id);
|
|
129
|
+
if (c.outcome === 'cancelled')
|
|
130
|
+
return { outcome: 'cancelled', order };
|
|
131
|
+
if (c.outcome === 'unknown')
|
|
132
|
+
return { outcome: 'unknown', kind: 'cancel', order };
|
|
133
|
+
ended(a.key, c.why);
|
|
134
|
+
return {
|
|
135
|
+
outcome: 'refused',
|
|
136
|
+
why: c.why === 'paid' ? 'not-open' : (c.why ?? 'failed'),
|
|
137
|
+
order,
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
const f = await shop.refund(a.token, provider, id);
|
|
141
|
+
if (f.outcome === 'refunded')
|
|
142
|
+
return {
|
|
143
|
+
outcome: 'refunded',
|
|
144
|
+
order,
|
|
145
|
+
...(f.refundCents !== undefined ? { refundCents: f.refundCents } : {}),
|
|
146
|
+
};
|
|
147
|
+
if (f.outcome === 'unknown')
|
|
148
|
+
return { outcome: 'unknown', kind: 'refund', order };
|
|
149
|
+
ended(a.key, f.why);
|
|
150
|
+
return { outcome: 'refused', why: f.why ?? 'failed', order };
|
|
151
|
+
},
|
|
152
|
+
buy: async (who, ask) => {
|
|
153
|
+
// ⚠️ SHUT UNLESS THE DEPLOYMENT OPENED IT: not a request is sent.
|
|
154
|
+
if (!o.buyOpen)
|
|
155
|
+
return { outcome: 'off' };
|
|
156
|
+
const a = auth(who);
|
|
157
|
+
if (!a)
|
|
158
|
+
return { outcome: 'not-signed-in' };
|
|
159
|
+
// ⚠️ THE GUEST'S OWN HOTEL ORDER, STILL LIVE (backend question #113: the order rides on one).
|
|
160
|
+
const b = await o.findBooking(ask.booking, who);
|
|
161
|
+
if (!b)
|
|
162
|
+
return { outcome: 'booking-refused', why: 'not-found' };
|
|
163
|
+
if (b.status !== 'confirmed' && b.status !== 'awaiting-payment')
|
|
164
|
+
return { outcome: 'booking-refused', why: 'not-live' };
|
|
165
|
+
// Check-out not past: the date as UTC today (the hotel's own clock is not known here).
|
|
166
|
+
const today = iso(o.now()).slice(0, 10);
|
|
167
|
+
if (!b.stay?.checkOut || b.stay.checkOut < today)
|
|
168
|
+
return { outcome: 'booking-refused', why: 'past' };
|
|
169
|
+
const r = await shop.buy(a.token, provider, {
|
|
170
|
+
itemId: ask.itemId,
|
|
171
|
+
...(ask.option ? { option: ask.option } : {}),
|
|
172
|
+
quantity: ask.quantity,
|
|
173
|
+
confirmationCode: b.confirmationCode,
|
|
174
|
+
lang: ask.lang,
|
|
175
|
+
}, { unitCents: ask.unitCents, currency: ask.currency });
|
|
176
|
+
if (r.outcome === 'not-signed-in')
|
|
177
|
+
o.signedOut?.(a.key);
|
|
178
|
+
return r;
|
|
179
|
+
},
|
|
180
|
+
};
|
|
181
|
+
};
|
|
182
|
+
/** Cents from a price a model passed (US$ or any currency's major units) - whole cents or nothing. */
|
|
183
|
+
export const unitCentsOf = (v) => {
|
|
184
|
+
const c = centsOf(v);
|
|
185
|
+
return c !== undefined && c > 0 ? c : undefined;
|
|
186
|
+
};
|
|
187
|
+
//# sourceMappingURL=shop-service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shop-service.js","sourceRoot":"","sources":["../../src/otaless/shop-service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AACjD,OAAO,EAQL,OAAO,GACR,MAAM,WAAW,CAAC;AAEnB,kGAAkG;AAClG,gGAAgG;AAChG,mGAAmG;AACnG,4FAA4F;AAC5F,EAAE;AACF,4FAA4F;AAC5F,sEAAsE;AAEtE;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,iEAAiE,CAAC;AAC/F,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,GAAW,EAAW,EAAE,CACzD,OAAO,GAAG,KAAK,QAAQ,IAAI,aAAa,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,CAAC;AAmF5D,MAAM,KAAK,GAAG,CAAC,GAAa,EAAU,EAAE,CAAC,GAAG,CAAC,SAAS,IAAI,GAAG,CAAC,SAAS,CAAC;AACxE,MAAM,IAAI,GAAG,CAAC,CAAS,EAAU,EAAE,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;AACpG,MAAM,YAAY,GAAG,GAAG,CAAC;AAEzB,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,CAAqB,EAAkB,EAAE;IACzE,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,CAAC,CAAC;IAC7B,MAAM,SAAS,GAAG,CAAC,CAAC,SAAS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AAC,CAAC,CAAC,EAAE,CAAC;gBAC7C,QAAQ,EAAE,GAAG,CAAC,QAAQ;gBACtB,gBAAgB,EAAE,CAAC,CAAC,gBAAgB;gBACpC,IAAI,EAAE,GAAG,CAAC,IAAI;aACf,EACD,EAAE,SAAS,EAAE,GAAG,CAAC,SAAS,EAAE,QAAQ,EAAE,GAAG,CAAC,QAAQ,EAAE,CACrD,CAAC;YACF,IAAI,CAAC,CAAC,OAAO,KAAK,eAAe;gBAAE,CAAC,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;YACxD,OAAO,CAAC,CAAC;QACX,CAAC;KACF,CAAC;AACJ,CAAC,CAAC;AAEF,sGAAsG;AACtG,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,CAAU,EAAsB,EAAE;IAC5D,MAAM,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;IACrB,OAAO,CAAC,KAAK,SAAS,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;AAClD,CAAC,CAAC"}
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import { type ShopClient } from './shop-client.js';
|
|
2
|
+
export type ShopLang = 'zh' | 'en';
|
|
3
|
+
export type ShopItem = {
|
|
4
|
+
id: string;
|
|
5
|
+
name: string;
|
|
6
|
+
description?: string;
|
|
7
|
+
category?: string;
|
|
8
|
+
priceCents: number;
|
|
9
|
+
currency: string;
|
|
10
|
+
unit?: string;
|
|
11
|
+
options: string[];
|
|
12
|
+
available: boolean;
|
|
13
|
+
/** Only an https picture on a host the deployment allows (`imageHosts`). */
|
|
14
|
+
imageUrl?: string;
|
|
15
|
+
};
|
|
16
|
+
export type ShopOrderStatus = 'awaiting-payment' | 'paid' | 'confirmed' | 'completed' | 'cancelled' | 'refunded' | 'failed' | 'unknown';
|
|
17
|
+
export type ShopOrder = {
|
|
18
|
+
id: string;
|
|
19
|
+
name: string;
|
|
20
|
+
totalCents: number;
|
|
21
|
+
currency: string;
|
|
22
|
+
status: ShopOrderStatus;
|
|
23
|
+
/**
|
|
24
|
+
* The checkout page of an order still awaiting payment - rebuilt from the allowed entry and the
|
|
25
|
+
* row's own path, only if it passed `checkoutLinkOf`. ⚠️ A row's `refundUrl` is NEVER handed out
|
|
26
|
+
* (questions #115: not known whom it is for or whether it refunds on a click).
|
|
27
|
+
*/
|
|
28
|
+
checkoutUrl?: string;
|
|
29
|
+
};
|
|
30
|
+
/** Why a read or a write was not made, in terms the tools can word. */
|
|
31
|
+
export type ShopWhy = 'not-enabled' | 'not-signed-in' | 'session-expired'
|
|
32
|
+
/** The shop's own sign-in is needed (`sign_in_required`) - not offered here yet; not a failure. */
|
|
33
|
+
| 'shop-sign-in' | 'busy' | 'failed';
|
|
34
|
+
export type ShopRead<T> = ({
|
|
35
|
+
ok: true;
|
|
36
|
+
} & T) | {
|
|
37
|
+
ok: false;
|
|
38
|
+
why: ShopWhy | 'not-found';
|
|
39
|
+
};
|
|
40
|
+
export type ShopCancelResult = {
|
|
41
|
+
outcome: 'cancelled' | 'refused' | 'unknown';
|
|
42
|
+
why?: ShopWhy | 'not-found' | 'not-awaiting' | 'paid' | 'in-progress' | 'checking';
|
|
43
|
+
};
|
|
44
|
+
export type ShopRefundResult = {
|
|
45
|
+
outcome: 'refunded' | 'refused' | 'unknown';
|
|
46
|
+
refundCents?: number;
|
|
47
|
+
why?: ShopWhy | 'not-found' | 'not-refundable' | 'in-progress' | 'checking';
|
|
48
|
+
};
|
|
49
|
+
export type ShopBuyRequest = {
|
|
50
|
+
itemId: string;
|
|
51
|
+
option?: string;
|
|
52
|
+
quantity: number;
|
|
53
|
+
/** The guest's own hotel booking this order rides on (questions #113): the caller checks it is theirs. */
|
|
54
|
+
confirmationCode: string;
|
|
55
|
+
lang: ShopLang;
|
|
56
|
+
guest?: {
|
|
57
|
+
name?: string;
|
|
58
|
+
email?: string;
|
|
59
|
+
phone?: string;
|
|
60
|
+
};
|
|
61
|
+
};
|
|
62
|
+
/** What the guest was shown and agreed to: the unit price the total is held to. */
|
|
63
|
+
export type ShopShown = {
|
|
64
|
+
unitCents: number;
|
|
65
|
+
currency: string;
|
|
66
|
+
};
|
|
67
|
+
export type ShopBuyResult = {
|
|
68
|
+
outcome: 'off';
|
|
69
|
+
} | {
|
|
70
|
+
outcome: 'busy' | 'not-signed-in' | 'session-expired' | 'shop-sign-in';
|
|
71
|
+
} | {
|
|
72
|
+
outcome: 'refused';
|
|
73
|
+
why: 'quantity' | 'confirmation-code' | 'shown' | 'not-found' | 'unavailable' | 'option' | 'in-progress' | 'checking' | 'backend';
|
|
74
|
+
} | {
|
|
75
|
+
outcome: 'price-changed';
|
|
76
|
+
now?: {
|
|
77
|
+
unitCents: number;
|
|
78
|
+
currency: string;
|
|
79
|
+
};
|
|
80
|
+
} | {
|
|
81
|
+
outcome: 'awaiting-payment';
|
|
82
|
+
order: ShopOrder;
|
|
83
|
+
checkoutUrl: string;
|
|
84
|
+
} | {
|
|
85
|
+
outcome: 'wrong-amount' | 'bad-link';
|
|
86
|
+
/** The order was cancelled: nothing was charged. */
|
|
87
|
+
cancelled: boolean;
|
|
88
|
+
/** The cancel did not work out - a person must look (no link is handed out). */
|
|
89
|
+
needsPerson: boolean;
|
|
90
|
+
orderId?: string;
|
|
91
|
+
} | {
|
|
92
|
+
/** ⚠️ The backend charged a card the guest did not choose (decision D): the order is kept. */
|
|
93
|
+
outcome: 'charged-without-asking';
|
|
94
|
+
order: ShopOrder;
|
|
95
|
+
totalCents?: number;
|
|
96
|
+
currency?: string;
|
|
97
|
+
/** The charge is above what the guest was shown. */
|
|
98
|
+
overShown: boolean;
|
|
99
|
+
needsPerson: true;
|
|
100
|
+
}
|
|
101
|
+
/** Not known what `/buy` made. `needsPerson`: a request went out and no single order of ours is
|
|
102
|
+
* found for it - a person looks, and no payment link is handed out. */
|
|
103
|
+
| {
|
|
104
|
+
outcome: 'unknown';
|
|
105
|
+
needsPerson?: true;
|
|
106
|
+
};
|
|
107
|
+
export type OtalessShopOptions = {
|
|
108
|
+
client: ShopClient;
|
|
109
|
+
/** The `providerCode`s switched on (`data.otaless.shop.providers`). */
|
|
110
|
+
providers: readonly string[];
|
|
111
|
+
/** Hosts a picture may be on (the hotel side's list plus `cdn.curless.ai`). */
|
|
112
|
+
imageHosts: readonly string[];
|
|
113
|
+
/**
|
|
114
|
+
* Where a checkout page may be: `host/path/` entries (`curless-retail-demo.myshopify.com/checkouts/`).
|
|
115
|
+
* ⚠️ A path is REQUIRED - an entry of a host alone matches nothing here (a Shopify host serves much
|
|
116
|
+
* else), and so does an entry naming `{order}` or `{token}` (those are the hotel side's forms).
|
|
117
|
+
*/
|
|
118
|
+
checkoutHosts: readonly string[];
|
|
119
|
+
/**
|
|
120
|
+
* The parameters that make `/buy` a checkout and nothing else - questions #103, unanswered at the
|
|
121
|
+
* time of writing. ⚠️ NONE (or empty), NO BUY: `buy()` answers `off` and sends nothing.
|
|
122
|
+
*/
|
|
123
|
+
buy?: {
|
|
124
|
+
params: Record<string, string | boolean>;
|
|
125
|
+
};
|
|
126
|
+
log?: (line: string) => void;
|
|
127
|
+
now?: () => number;
|
|
128
|
+
};
|
|
129
|
+
export type OtalessShop = {
|
|
130
|
+
items: (provider: string, q: {
|
|
131
|
+
keyword?: string;
|
|
132
|
+
category?: string;
|
|
133
|
+
maxPrice?: number;
|
|
134
|
+
limit?: number;
|
|
135
|
+
lang: ShopLang;
|
|
136
|
+
}) => Promise<ShopRead<{
|
|
137
|
+
items: ShopItem[];
|
|
138
|
+
}>>;
|
|
139
|
+
item: (provider: string, id: string, lang: ShopLang) => Promise<ShopRead<{
|
|
140
|
+
item: ShopItem;
|
|
141
|
+
}>>;
|
|
142
|
+
orders: (token: string, provider: string, opts?: {
|
|
143
|
+
lang?: ShopLang;
|
|
144
|
+
refresh?: boolean;
|
|
145
|
+
}) => Promise<ShopRead<{
|
|
146
|
+
orders: ShopOrder[];
|
|
147
|
+
}>>;
|
|
148
|
+
cancel: (token: string, provider: string, orderId: string) => Promise<ShopCancelResult>;
|
|
149
|
+
refund: (token: string, provider: string, orderId: string) => Promise<ShopRefundResult>;
|
|
150
|
+
buy: (token: string, provider: string, req: ShopBuyRequest, shown: ShopShown) => Promise<ShopBuyResult>;
|
|
151
|
+
};
|
|
152
|
+
/**
|
|
153
|
+
* Cents from a backend number or numeric string: whole cents only, finite, not negative. ⚠️ A third
|
|
154
|
+
* decimal is not rounded away - 75.655 is not a price we can compare, it is not taken (an amount
|
|
155
|
+
* half a cent over would otherwise pass as equal).
|
|
156
|
+
*/
|
|
157
|
+
export declare const centsOf: (v: unknown) => number | undefined;
|
|
158
|
+
export declare const orderStatusOf: (v: unknown) => ShopOrderStatus;
|
|
159
|
+
export declare const createOtalessShop: (o: OtalessShopOptions) => OtalessShop;
|
|
160
|
+
//# sourceMappingURL=shop.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shop.d.ts","sourceRoot":"","sources":["../../src/otaless/shop.ts"],"names":[],"mappings":"AAGA,OAAO,EAEL,KAAK,UAAU,EAMhB,MAAM,kBAAkB,CAAC;AAmB1B,MAAM,MAAM,QAAQ,GAAG,IAAI,GAAG,IAAI,CAAC;AAEnC,MAAM,MAAM,QAAQ,GAAG;IACrB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,SAAS,EAAE,OAAO,CAAC;IACnB,4EAA4E;IAC5E,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,MAAM,MAAM,eAAe,GACvB,kBAAkB,GAClB,MAAM,GACN,WAAW,GACX,WAAW,GACX,WA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